Customizing the Order Number Format

TABLE OF CONTENTS

Introduction

Order numbers are automatically generated in Znode but sometimes there is a business requirement to have a specific format for the order number. The following information outlines where the order number is generated so it can be overridden.

An order number is generated by calling the GenerateOrderNumber method in the following scenarios:

  1. When creating an order from the webstore
  2. When creating an order via the Admin Console
  3. Converting Quote to an Order in the webstore or Admin Console
  4. If the OrderNumber passed in the Model is null during creating an order (this is the additional check on the service level to generate the order number)
    1. The following is the method call:
      submitOrderModel.OrderNumber = !string.IsNullOrEmpty(model.OrderNumber)? model.OrderNumber : GenerateOrderNumber(submitOrderModel, portalId);

Required Customization Overview:

The CheckoutAgent.cs is a core class found in the Znode Source. In order to add custom business logic to this Znode Source class, we will show how to hook into the source class, rename the class, and add custom business logic to use it in the Znode SDK. In order to properly do this, we will register the custom class with our inversion of the control framework called Autofac, using dependency registration. We will cover customizing the Webstore, Admin, and API projects in the Znode SDK.

Webstore Changes

The GenerateOrderNumber() method in the CheckoutAgent.cs class must be overridden to create a custom order number. To do so the following code changes need to be made:

  1. In Znode.Webstore.Custom library creates a new class called CustomCheckoutAgent.cs inside the Agents folder
  2. This class should be inherited from CheckoutAgent.cs class
  3. Override the GenerateOrderNumber() in the CustomCheckoutAgent.cs class

    Below is the sample code snippet for the change:

Also, please make sure to Register the Dependency Injection for Agents: Znode.Webstore.Custom\Helper\CustomDependancyRegistration.cs
builder.RegisterType<CustomCheckoutAgent>().As<ICheckoutAgent>().InstancePerDependency();

Required Admin Application Changes

The GenerateOrderNumber() method in the OrderAgent.cs class must be overridden to create a custom order number. To do so the following code changes need to be made:

  1. In Znode.Admin.Custom library creates a new class called CustomOrderAgent.cs inside the Agents folder
  2. This class should be inherited from OrderAgent.cs class
  3. Override the GenerateOrderNumber() in the CustomOrderAgent.cs class

    Below is the sample code snippet for the change:


Also, make sure to Register the Dependency Injection for Agents: Znode.Admin.Custom\Helper\DependencyRegistration.cs
builder.RegisterType<CustomOrderAgent>().As<IOrderAgent>().InstancePerLifetimeScope();

Required API changes:

The following changes are required:

  1. In project Znode.API.Custom:
  2. Add this to DependencyRegistration.cs: builder.RegisterType<CustomOrderService>().As<OrderService>().InstancePerRequest();
  3. Create a new class called CustomOrderService.cs with this content:

    Below is the sample code snippet for the change



Note - It is suggested that a custom order number should be created while placing an order from the Webstore or Admin Console.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.