Order Workflow

Order Workflow

An Order is a collection of one or more ProductVariants which can be purchased by a Customer. Orders are represented internally by the Order entity and in the GraphQL API by the Order type.

Order State

Every Order has a state property of type OrderState. The following diagram shows the default states and how an Order transitions from one to the next.

Structure of an Order

In Vendure an Order consists of one or more OrderLines (representing a given quantity of a particular SKU), which in turn contain one or more OrderItems (which represent the individual physical units).

Here is a simplified diagram illustrating this relationship:

So if the customer adds 2 Widgets to the Order, there will be one OrderLine containing two OrderItems, one for each of the added Widgets.

Shop client order workflow

The following is a description of the flow and related GraphQL operations which are used when dealing with Orders in a customer-facing client application (i.e. a storefront).

  1. activeOrder query returns the currently-active Order for the session.
  2. addItemToOrder mutation adds an item to the order. The first time it is called will also create a new Order for the session.
  3. adjustOrderLine mutation is used to adjust the quantity of an OrderLine.
  4. removeOrderLine mutation removes an OrderLine from the Order.
  5. setCustomerForOrder mutation specifies the Customer details (required if the customer is not logged in as an authenticated user).
  6. setOrderShippingAddress mutation sets the shipping address for the Order.
  7. eligibleShippingMethods query returns all available shipping methods based on the customer’s shipping address and the contents of the Order.
  8. setOrderShippingMethod mutation sets the shipping method to use.
  9. addPaymentToOrder mutation adds a payment to the Order. If the payment amount equals the order total, then the Order will be transitioned to either the PaymentAuthorized or PaymentSettled state (depending on how the payment provider is configured) and the order process is complete from the customer’s side.