Module: SolidusLegacyPromotions::SpreeOrderUpdaterDecorator

Defined in:
app/decorators/solidus_legacy_promotions/models/spree_order_updater_decorator.rb

Instance Method Summary collapse

Instance Method Details

#update_adjustment_totalObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/decorators/solidus_legacy_promotions/models/spree_order_updater_decorator.rb', line 5

def update_adjustment_total
  recalculate_adjustments

  all_items = line_items + shipments
  order_tax_adjustments = adjustments.select(&:eligible?).select(&:tax?)

  order.adjustment_total = all_items.sum(&:adjustment_total) + adjustments.select(&:eligible?).sum(&:amount)
  order.included_tax_total = all_items.sum(&:included_tax_total) + order_tax_adjustments.select(&:included?).sum(&:amount)
  order.additional_tax_total = all_items.sum(&:additional_tax_total) + order_tax_adjustments.reject(&:included?).sum(&:amount)

  update_order_total
end

#update_item_totalsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/decorators/solidus_legacy_promotions/models/spree_order_updater_decorator.rb', line 18

def update_item_totals
  [*line_items, *shipments].each do |item|
    # The cancellation_total isn't persisted anywhere but is included in
    # the adjustment_total
    item.adjustment_total = item.adjustments.
      select(&:eligible?).
      reject(&:included?).
      sum(&:amount)

    if item.changed?
      item.update_columns(
        promo_total:          item.promo_total,
        included_tax_total:   item.included_tax_total,
        additional_tax_total: item.additional_tax_total,
        adjustment_total:     item.adjustment_total,
        updated_at:           Time.current,
      )
    end
  end
end