Ordermodel is one of the key models in Spree. It provides a central place around which to collect information about a customer order - including line items, adjustments, payments, addresses, return authorizations, and shipments.
number: The unique identifier for this order. It begins with the letter R and ends in a 9-digit number. This number is shown to the users, and can be used to find the order by calling
item_total: The sum of all the line items for this order.
adjustment_total: The sum of all adjustments on this order.
total: The result of the sum of the
payment_total: The total value of all finalized payments.
shipment_total: The total value of all shipments' costs.
additional_tax_total: The sum of all shipments' and line items'
included_tax_total: The sum of all shipments' and line items'
promo_total: The sum of all shipments', line items' and promotions'
user_id: The ID for the corresponding user record for this order. Stored only if the order is placed by a signed-in user.
completed_at: The timestamp of when the order was completed.
bill_address_id: The ID for the related
Addressobject with billing address information.
ship_address_id: The ID for the related
Addressobject with shipping address information.
shipping_method_id: The ID for the related
created_by_id: The ID of object that created this order.
special_instructions: Any special instructions for the store to do with this order. Will only appear if
Spree::Config[:shipping_instructions]is set to
currency: The currency for this order. Determined by the
Store#default_currencycurrency in which this order was created
last_ip_address: The last IP address used to update this order in the frontend.
channel: The channel specified when importing orders from other stores. e.g. amazon.
item_count: The total value of line items' quantity.
approver_id: The ID of user that approved this order.
confirmation_delivered: Boolean value indicating that confirmation email was delivered.
token: The token stored corresponding to token stored in cookies. In older Spree versions this attribute was called
canceler_id: The ID of user that canceled this order.
store_id: The ID of
Storein which this order was created.
outstanding_balance: The outstanding balance for the order, calculated by taking the
display_item_total: A "pretty" version of
display_adjustment_total: Same as above, except for
display_total: Same as above, except for
display_outstanding_balance: Same as above, except for
cart- initial state
address- Cart moved to Checkout
delivery- buyer has added Shipping and Billing addresses
payment- buyer selected delivery option
confirm- buyer added payment option (if required)
complete- order was placed
paymentstate will only be triggered if
confirmstate will only be triggered if
completestate can only be reached in one of two ways:
nexton that object. If this returns
false, then the order does not meet the criteria. To work out why it cannot transition, check the result of an
shipment_statecolumn which indicates the state of all shipments. Order can have multiple shipments.
shipped- all Shipments are in the
partial- at least one Shipment has a state of
shippedand there is another Shipment with a state other than
shippedor there are InventoryUnits associated with the order that have a state of
soldbut are not associated with a Shipment
ready- all Shipments are in the
backorder- there is backordered inventory associated with an order
pending- all Shipments are in the
payment_statecolumn which indicates the state of all payments. Order can have multiple payments.
payment_totalis equal to
payment_totalis less than
payment_totalis greater than
failed- most recent payment is in the
void- order is canceled and
Addressobjects. The shipping address indicates where the order's product(s) should be shipped to. This address is used to determine which shipping methods are available for an order.
ReturnAuthorizationobjects. These records keeps track of which items have been authorized for return and how the user will be compensated -- either via exchanging the item(s) or a reimbursement.
Orderobject within code and you wish to update the order's totals -- including associated adjustments and shipments -- call the
update_with_updater!method on that object, which calls out to the
payment_stateto a different value, calling
update_with_updater!will cause the
payment_stateto be recalculated for that order.
LineItemwithin the order had its price changed. Calling
update_with_updater!will cause the totals for the order to be updated, the adjustments for the order to be recalculated, and then a final total to be established.