Sha256: e69cd6d16c63970c0da121733f78cb3d066c2b98c3b24089d0fc89ae4fe6208b
Contents?: true
Size: 1002 Bytes
Versions: 64
Compression:
Stored size: 1002 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.eligible.sum(:amount).abs if order.adjustments.eligible.any? amounts.min * -1 end end end end end
Version data entries
64 entries across 64 versions & 1 rubygems