Class: Spree::Adjustable::AdjustmentsUpdater

Inherits:
Object
  • Object
show all
Defined in:
app/models/spree/adjustable/adjustments_updater.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adjustable) ⇒ AdjustmentsUpdater


8
9
10
11
# File 'app/models/spree/adjustable/adjustments_updater.rb', line 8

def initialize(adjustable)
  @adjustable = adjustable
  adjustable.reload if shipment? && adjustable.persisted?
end

Class Method Details

.update(adjustable) ⇒ Object


4
5
6
# File 'app/models/spree/adjustable/adjustments_updater.rb', line 4

def self.update(adjustable)
  new(adjustable).update
end

Instance Method Details

#updateObject


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/spree/adjustable/adjustments_updater.rb', line 13

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