Cart & Order flows

A Cart/Order flow is a set of states through which a cart or an order progresses – e.g. New, Paid, Goods dispatched, and Completed – before it is converted to an order or marked as complete.

Cart and order flows are therefore used to keep track of and control how a cart or an order should be processed:

  • Cart flows are typically used on solutions where multiple carts are being created over an extended period, and where multiple parties have a say on when the cart should be checked out. This could be a B2B setup where e.g. apparel stores spent a few days adding spring collection items to a cart before finalizing their order.
  • Order flows are used on most B2C solutions to control the order processing procedure – e.g. the timespan between an order being placed and it being delivered to the customer. This typically involves steps such as Order received, order collected, tracking generated, order shipped, and perhaps completed.

Of course, each flow can (and should) be tailored to the solution in question – and in some cases a solution will use both cart flows and order flows at the same time to control the procedure both before and after an order is placed.

To create an order or cart flow:

  • Go to Settings > Ecommerce > Orders > Order flows/Cart flows as appropriate
  • Click New order flow/New cart flow in the toolbar
  • Provide a name and optionally a description
  • If this should be the default flow check the Default checkbox
  • Save

This creates a new – but empty – order or cart flow. Next you must add states to it – the individual steps in the flow. 

Both order and cart flows consist of states – steps in a flow where something is supposed to be done or happen before proceeding to the next state:

  • Order states are used to describe a workflow when processing orders after they have been placed, e.g. Received, Processing, Charged, and Shipped. They are changed from the backend.
  • Cart states are used to describe a workflow before a cart is converted to an order, e.g. New, approved, submitted. They can be changed from both backend and frontend.

To create a new state, click New state in the toolbar to open the edit view (Figure 2.1).

Figure 2.1 Creating a new order state

From here, you must:

  • Name the state and optionally provide a description for it.
  • Check the default checkbox, if you want new carts/orders to be created with this state set.
  • Decide if you want to include or exclude the state from the Ecommerce statistics.

In the Notifications area you can set up automatic emails for customers or others when the cart or order enters this state:

  • Specify a subject, a sender name, and a sender email. Use {OrderID} in the subject line to include the order id.
  • Check one or more of the recipient email options:
    • Send to billing email
    • Send to shipping email
    • Send to order field email – if this is selected you must also select a custom order field which should then contain an email address when the state is set
  • Select an email template to use for the emails selected above

You can also manually add emails to the Send to others field – and select an email template to use for this email. This field is typically used to contact key people inside the organization when an order is set to a specific state, whereas the other notifications are typically used to notify the customer.

When you’re happy with the state save it and repeat as necessary until the cart or order flow contains all the necessary steps.

As described in the previous section, order and cart states look similar but are used in different ways:

  • Order states are used to describe a workflow when processing orders. They are changed from the backend.
  • Cart states are used to describe a workflow before a cart is converted to an order.. They can be changed from both backend and frontend.

Too change cart or order states from the backend you open the cart or order and then select a new state in the ribbon bar dropdown (Figure 3.1) and then save.

Figure 3.1 Changing a cart or order state

To change a cart state from the frontend you submit a form with specific parameters to a customer center app, either by actually rendering the form inside customer center template or by simplty posting to it.

The form must have the Id ChangeDraftStatusForm and have the following parameters:

Parameter

Value

Required

Comment

CartID

A cart id

Yes

 

StateID

A cart state id

Yes

 

In this example we use the current cart context to retrieve a list of cart states which are then rendered in a drop down selector. The form is submitted to the page with ID# 2, since that’s where my customer center app is, with the url parameter CC=Carts because…well, because the customer center is weird and expects it.

RAZOR
@if (Dynamicweb.Ecommerce.Common.Context.Cart != null) { var currentcart = Dynamicweb.Ecommerce.Common.Context.Cart; var cartstates = Dynamicweb.Ecommerce.Orders.OrderState.GetAllCartStates(currentcart.OrderState.OrderFlowId); <!--Cart states--> <div> <h4>Cart State</h4> <div>Current state: @currentcart.OrderState.Name (@currentcart.OrderState.OrderFlowId)</div> <form method="post" id="ChangeDraftStatusForm" action="/Default.aspx?ID=2&CC=Carts"> <input type="hidden" name="CartID" id="CartID" value="@currentcart.Id" /> <select name="StateId" id="StateID"> @foreach (Dynamicweb.Ecommerce.Orders.OrderState state in cartstates) { <option value="@state.Id">@state.Name</option> } </select> <button type="submit">Change state</button> </form> </div> }
database

These are the database tables relevant for order flows & order states:

EcomOrderFlow

Contains order flow setup from Settings -> Ecom -> Orders -> Order flows.

Field name Data type Length
OrderFlowId int 4
OrderFlowIsDefault bit 1
OrderFlowName nvarchar 255
OrderFlowDescription nvarchar Max
OrderFlowOrderType int 4

EcomOrderStates

Contains definitions of individual order states in an order flow (OrderFlowId).

Field name Data type Length
OrderStateId nvarchar 50
OrderStateName nvarchar 255
OrderStateDescription nvarchar Max
OrderStateIsDefault bit 1
OrderStateDontUseInstatistics bit 1
OrderStateIsDeleted bit 1
OrderStateMailTemplate nvarchar 255
OrderFlowId int 4
OrderStateMailSender nvarchar 255
OrderStateMailSenderName nvarchar 255
OrderStateMailSubject nvarchar 255
OrderStateAutoId int 4
OrderStateSendToCustomer bit 1
OrderStateOthersMailTemplate nvarchar 255
OrderStateOthersRecipients nvarchar Max
OrderStateSortOrder int 4
OrderStateOrderType int 4
OrderStateAllowOrder bit 1
OrderStateAllowEdit bit 1
OrderStateSendToDeliveryEmail bit 1
OrderStateSendToField bit 1
OrderStateCustomRecipientField nvarchar 255

EcomOrderStateRules

Defines flow between order states (OrderStateRuleFromState -> OrderStateRuleToState).

Field name Data type Length
OrderStateRuleId int 4
OrderStateRuleFromState nvarchar 50
OrderStateRuleToState nvarchar 50