Sha256: a4a4f51964f4eeecc8fc227591ad194b13f8731551c8dd63e9864fab4ea15612
Contents?: true
Size: 984 Bytes
Versions: 38
Compression:
Stored size: 984 Bytes
Contents
module Spree class Promotion module Actions class CreateItemAdjustments < PromotionAction include Spree::CalculatedAdjustments include Spree::AdjustmentSource before_validation -> { self.calculator ||= Calculator::PercentOnLineItem.new } 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 def compute_amount(line_item) return 0 unless promotion.line_item_actionable?(line_item.order, line_item) amounts = [line_item.amount, compute(line_item)] order = line_item.order # Prevent negative order totals amounts << order.amount - order.adjustments.sum(:amount).abs if order.adjustments.any? amounts.min * -1 end end end end end
Version data entries
38 entries across 38 versions & 1 rubygems