You are here: Order System > Changing the Sequence for Order Numbers

Changing the Sequence for Order Numbers

Overview

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's appropriate to your implementation is set for the TrackingNumber property.

How it works

The Cart has a public delegate property called CreateOrderNumber. The signature for this delegate is:

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. Here's the portion of the SaveAsPurchaseOrder method that performs this:

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

 

Here's an outline you could use to implement a custom order number generator:

//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();

 


Version: EPiServer Commerce 1 R2 SP2| Last updated: 2012-06-29 | Copyright © EPiServer AB | Send feedback to us