Sha256: 9be10dc72775ff1a7b7751318723286b472d4d1f674e8975053e04f52cd76e30

Contents?: true

Size: 1.12 KB

Versions: 43

Compression:

Stored size: 1.12 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.persisted?
      end

      def update
        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

43 entries across 43 versions & 1 rubygems

Version Path
spree_core-3.2.9 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.14 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.6 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.2.8 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.13 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.5 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.4 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.2.7 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.12 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.3 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.2.6 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.11 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.10 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.2 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.2.5 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.9 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.1 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.2.4 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.1.8 app/models/spree/adjustable/adjustments_updater.rb
spree_core-3.3.0 app/models/spree/adjustable/adjustments_updater.rb