Orders

When a cart is completed, it becomes an order. You can view orders in the Commerce → Orders section of the Control Panel.

When a cart becomes an order, the following things happen:

  1. The order gets a dateOrdered date.
  2. The isCompleted order attribute is set to true.
  3. The default order status is set on the order and any emails for this status are sent.
  4. The order reference number is generated for the order, based on the ‘Order Reference Number Format‘ setting found in Commerce → Settings → General Settings section of the Control Panel.

Order Number

The order number is a hash, generated when the cart is created. It exists from initial creation for the entire life of the order.
This is different to the order reference number that is only generated after the cart has been completed and becomes an order.

Short Order Number

The short order number is the first 7 characters of the order number. This is short enough to still be unique and is a little friendlier to customers, although not as friendly as the order reference number.

Order Reference Number

The order reference number is generated on cart completion by the ‘Order Reference Number Format’ in general settings.

This number is usually the best to use as the customer facing identifier of the order.

The ‘Order Reference Number Format’ is a mini Twig template, which will be rendered when the order is completed.

Attributes on the order can be accessed as well as Twig filters and functions, for example:

{{ object.dateCompleted|d('Y') }}-{{ id }}

Ouput:

2018-43

Please note in the above example, the ID is the element ID, which is not sequential.

A sequential number can be generated by the use of Craft’s seq() Twig function, which generates a next unique number based on the name parameter passed to it.

The seq() function takes the following parameters:

  1. A key name. If this name is changes, a new sequence starting at one is started. See Craft docs for more information.
  2. An optional padding character length. For example if the next sequence number is 14 and the padding length is 8, the generation number will be 00000014

For example:

{{object.dateCompleted|date('Y')}}-{{ seq(object.dateCompleted|date('Y'), 8) }}

Ouput:

2018-00000023

In the above example we have used the year as the sequence name so that we automatically get a new sequence starting at 1 when the next year arrives.