This content is archived. See latest version here

Last updated: Mar 31 2014

When a purchase is submitted by a customer, the cart is converted to a PurchaseOrder. This is done by calling the Cart.SaveAsPurchaseOrder method. When this method is called, an order number (PurchaseOrder.TrackingNumber property) is automatically assigned to the new PurchaseOrder using a default algorithm. However, the algorithm can be overridden so that an order number that is more appropriate to your implementation is set for the TrackingNumber property.

Classes referred to here are available in the following namespaces:

How it works

The Cart has a public delegate property called CreateOrderNumber.

Example: the delegate signature for CreateOrderNumber

C#
public delegate string CreateOrderNumber(Cart cart);

This delegate is null by default. When the SaveAsPurchaseOrder method is executed and no delegate is set, the default delegate is created and executed.

However, if the delegate is set with a custom method prior to executing the SaveAsPurchaseOrder method, the custom delegate will be run.

Example: the part of the SaveAsPurchaseOrder method that runs the custom delegate

C#
// from inside SaveAsPurchaseOrder method
          // Set tracking number
          if (this.OrderNumberMethod == null)
          {
            this.OrderNumberMethod = new CreateOrderNumber(GenerateOrderNumber);
          }
          purchaseOrder.TrackingNumber = OrderNumberMethod(this);

Example: implementing a custom order number generator

C#
//custom order number method
          private string CustomOrderNumber(Cart cart)
          {
            //implement custom logic here to return a custom order number in string format
          }

          ...
          //somewhere in your method where you are completing the checkout process
          //Set the Cart order generator delegate
          CartHelper.Cart.OrderNumberMethod = new CreateOrderNumber(CustomOrderNumber);

          //now convert the cart into a purchase order
          CartHelper.Cart.SaveAsPurchaseOrder();

Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/