Class: Spree::Promotion::Actions::CreateLineItems

Inherits:
Spree::PromotionAction show all
Defined in:
app/models/spree/promotion/actions/create_line_items.rb

Instance Method Summary collapse

Instance Method Details

#perform(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/spree/promotion/actions/create_line_items.rb', line 11

def perform(options = {})
  return unless order = options[:order]
  return unless eligible?(order)
  promotion_action_line_items.each do |item|
    current_quantity = order.quantity_of(item.variant)
    if current_quantity < item.quantity
      order.add_variant(item.variant, item.quantity - current_quantity)
      order.update!
    end
  end
end