Sha256: 897aa075545d66ac891454c730c9411e5c9dd921ee223772710e3e6ae6b23192

Contents?: true

Size: 737 Bytes

Versions: 7

Compression:

Stored size: 737 Bytes

Contents

module Spree
  class Promotion
    module Actions
      class CreateLineItems < PromotionAction
        has_many :promotion_action_line_items, :foreign_key => :promotion_action_id
        accepts_nested_attributes_for :promotion_action_line_items
        attr_accessible :promotion_action_line_items_attributes


        def perform(options = {})
          return unless order = options[: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
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
spree_promo-1.3.3 app/models/spree/promotion/actions/create_line_items.rb
spree_promo-1.3.2 app/models/spree/promotion/actions/create_line_items.rb
spree_promo-1.3.1 app/models/spree/promotion/actions/create_line_items.rb
spree_promo-1.3.0 app/models/spree/promotion/actions/create_line_items.rb
spree_promo-1.3.0.rc2 app/models/spree/promotion/actions/create_line_items.rb
dup_spree_promo-1.3.0.rc1 app/models/spree/promotion/actions/create_line_items.rb
spree_promo-1.3.0.rc1 app/models/spree/promotion/actions/create_line_items.rb