Class: Spree::Promotion::Actions::CreateItemAdjustments

Inherits:
Spree::PromotionAction show all
Includes:
AdjustmentSource, CalculatedAdjustments
Defined in:
app/models/spree/promotion/actions/create_item_adjustments.rb

Instance Method Summary collapse

Methods inherited from Base

belongs_to_required_by_default, page, spree_base_scopes

Methods included from Spree::Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Method Details

#compute_amount(line_item) ⇒ Object


18
19
20
21
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 18

def compute_amount(line_item)
  return 0 unless promotion.line_item_actionable?(line_item.order, line_item)
  [line_item.amount, compute(line_item)].min * -1
end

#perform(options = {}) ⇒ Object


10
11
12
13
14
15
16
# File 'app/models/spree/promotion/actions/create_item_adjustments.rb', line 10

def perform(options = {})
  order = options[:order]
  promotion = options[:promotion]
  create_unique_adjustments(order, order.line_items) do |line_item|
    promotion.line_item_actionable?(order, line_item)
  end
end