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:
- When creating an order from the webstore
- When creating an order via the Admin Console
- Converting Quote to an Order in the webstore or Admin Console
- 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)
- The following is the method call:
submitOrderModel.OrderNumber = !string.IsNullOrEmpty(model.OrderNumber)? model.OrderNumber : GenerateOrderNumber(submitOrderModel, portalId);
- The following is the method call:
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:
- In Znode.Webstore.Custom library creates a new class called CustomCheckoutAgent.cs inside the Agents folder
- This class should be inherited from CheckoutAgent.cs class
- 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:
- In Znode.Admin.Custom library creates a new class called CustomOrderAgent.cs inside the Agents folder
- This class should be inherited from OrderAgent.cs class
- 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:
- In project Znode.API.Custom:
- Add this to DependencyRegistration.cs: builder.RegisterType<CustomOrderService>().As<OrderService>().InstancePerRequest();
- 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.