Module: SpreeCmCommissioner::OrderUpdaterDecorator

Defined in:
app/models/spree_cm_commissioner/order_updater_decorator.rb

Instance Method Summary collapse

Instance Method Details

#persist_totals ⇒ Object

Duplicates Spree::OrderUpdater#persist_totals' update_columns call (spree_core 4.5.3) rather than calling super + a second update_columns for service_fee_total, to keep this to a single UPDATE per order -- with read replicas/connection pooling in front of this, a second round-trip per persist_totals call isn't free. Must be kept in sync if core ever changes that column list.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/spree_cm_commissioner/order_updater_decorator.rb', line 22

def persist_totals
  order.update_columns( # rubocop:disable Rails/SkipsModelValidations
    payment_state: order.payment_state,
    shipment_state: order.shipment_state,
    item_total: order.item_total,
    item_count: order.item_count,
    adjustment_total: order.adjustment_total,
    included_tax_total: order.included_tax_total,
    additional_tax_total: order.additional_tax_total,
    payment_total: order.payment_total,
    shipment_total: order.shipment_total,
    promo_total: order.promo_total,
    total: order.total,
    service_fee_total: order.service_fee_total,
    updated_at: Time.current
  )
end

#update_adjustment_total ⇒ Object

Rolls line items' service_fee_total up into the order (display total only — the fee is already folded into order.adjustment_total/total via the non_taxable_adjustment_total bucket, see Adjustable::Adjuster::ServiceFee).



12
13
14
15
# File 'app/models/spree_cm_commissioner/order_updater_decorator.rb', line 12

def update_adjustment_total
  super
  order.service_fee_total = line_items.sum(:service_fee_total)
end

#update_item_total ⇒ Object

override



4
5
6
7
# File 'app/models/spree_cm_commissioner/order_updater_decorator.rb', line 4

def update_item_total
  order.item_total = line_items.sum(&:amount)
  update_order_total
end