Class: Spree::OrderUpdater
- Inherits:
-
Object
- Object
- Spree::OrderUpdater
- Defined in:
- app/models/spree/order_updater.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
Instance Method Summary collapse
-
#initialize(order) ⇒ OrderUpdater
constructor
A new instance of OrderUpdater.
-
#recalculate ⇒ Object
(also: #update)
This is a multi-purpose method for processing logic related to changes in the Order.
-
#update_payment_state ⇒ Object
Updates the
payment_state
attribute according to the following logic:. -
#update_shipment_state ⇒ Object
Updates the
shipment_state
attribute according to the following logic:.
Constructor Details
#initialize(order) ⇒ OrderUpdater
Returns a new instance of OrderUpdater.
8 9 10 |
# File 'app/models/spree/order_updater.rb', line 8 def initialize(order) @order = order end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
5 6 7 |
# File 'app/models/spree/order_updater.rb', line 5 def order @order end |
Instance Method Details
#recalculate ⇒ Object Also known as: update
This is a multi-purpose method for processing logic related to changes in the Order. It is meant to be called from various observers so that the Order is aware of changes that affect totals and other values stored in the Order.
This method should never do anything to the Order that results in a save call on the object with callbacks (otherwise you will end up in an infinite recursion as the associations try to save and then in turn try to call update!
again.)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/spree/order_updater.rb', line 19 def recalculate order.transaction do update_item_count update_shipment_amounts update_totals if order.completed? update_payment_state update_shipments update_shipment_state end Spree::Bus.publish(:order_recalculated, order:) persist_totals end end |
#update_payment_state ⇒ Object
Updates the payment_state
attribute according to the following logic:
paid when payment_total
is equal to total
balance_due when payment_total
is less than total
credit_owed when payment_total
is greater than total
failed when most recent payment is in the failed state void when the order has been canceled and the payment total is 0
The payment_state
value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
63 64 65 66 67 68 69 |
# File 'app/models/spree/order_updater.rb', line 63 def update_payment_state log_state_change('payment') do order.payment_state = determine_payment_state end order.payment_state end |
#update_shipment_state ⇒ Object
Updates the shipment_state
attribute according to the following logic:
shipped when all Shipments are in the “shipped” state partial when at least one Shipment has a state of “shipped” and there is another Shipment with a state other than “shipped”
or there are InventoryUnits associated with the order that have a state of "sold" but are not associated with a Shipment.
ready when all Shipments are in the “ready” state backorder when there is backordered inventory associated with an order pending when all Shipments are in the “pending” state
The shipment_state
value helps with reporting, etc. since it provides a quick and easy way to locate Orders needing attention.
46 47 48 49 50 51 52 |
# File 'app/models/spree/order_updater.rb', line 46 def update_shipment_state log_state_change('shipment') do order.shipment_state = determine_shipment_state end order.shipment_state end |