Sha256: 25f4ef9308ebe39e2a1691a08a4ea957bc4aed616c4e4384675d4817de4f43a6
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
module Spree module Adjustable class AdjustmentsUpdater def self.update(adjustable) new(adjustable).update end def initialize(adjustable) @adjustable = adjustable adjustable.reload if shipment? && adjustable && adjustable.persisted? end def update return unless @adjustable return unless @adjustable.persisted? totals = { non_taxable_adjustment_total: 0, taxable_adjustment_total: 0 } adjusters.each do |klass| klass.adjust(@adjustable, totals) end persist_totals totals end private def persist_totals(totals) attributes = totals attributes[:adjustment_total] = totals[:non_taxable_adjustment_total] + totals[:taxable_adjustment_total] + totals[:additional_tax_total] attributes[:updated_at] = Time.current @adjustable.update_columns(totals) end def shipment? @adjustable.is_a?(Shipment) end def adjusters Rails.application.config.spree.adjusters end end end end
Version data entries
3 entries across 3 versions & 1 rubygems