Sha256: 8ea95740e5301eb6e83b6c71fad2b1f65a0cd8bedf38c0a2c9e83e52c81278ab

Contents?: true

Size: 738 Bytes

Versions: 5

Compression:

Stored size: 738 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.contents.add(item.variant, item.quantity - current_quantity)
              order.update!
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-2.0.3 app/models/spree/promotion/actions/create_line_items.rb
spree_core-2.0.2 app/models/spree/promotion/actions/create_line_items.rb
spree_core-2.0.1 app/models/spree/promotion/actions/create_line_items.rb
spree_core-2.0.0 app/models/spree/promotion/actions/create_line_items.rb
spree_core-2.0.0.rc1 app/models/spree/promotion/actions/create_line_items.rb