TABLE OF CONTENTS
- Creating a Custom Promotion
- Steps to extend the promotion engine in Znode SDK
Creating a Custom Promotion
There are three types of Promotions in Znode that are offered OOTB and the discount is applied based on these types - Cart Promotion, Price Promotion, Product Promotion.
Cart promotions apply discounts to customers' carts.
Promotions are applied to the price.
Discounts are based on specific products (SKUs)
Steps to extend the promotion engine in Znode SDK
There are two areas where promotion changes need to be implemented in Znode.
- Database Changes: The database changes will consist of the following tables ZnodePromotionType, ZnodePromotionAttribute, ZnodePromotionDiscountAttributeMapper. The PromotionAttributeId required while adding data in ZnodePromotionDiscountAttributeMapper will be dependent on the ZnodePromotionAttribute table.
- Code Changes: The changes needed on the C# side are, we need to create Custom Library, Custom Promotion Manager, Custom Promotion Helper class, Custom Promotion specific class, Custom Promotion Controllers for Admin, API, and Webstore also we need to register Dependency Injection types as required
Depending on the type of promotion you want to create you need to add some custom values in the Znode Database. The tables needed are ZnodePromotionType, ZnodePromotionAttribute, and ZnodePromotionDiscountAttributeMapper. To add a new custom promotion in Znode we have to first add values to the database
- First, we need to add the data in the ZnodePromotionType table depending on the type of promotion. Note: In ZnodePromotionType table consists of two columns, ClassType and ClassName. The ClassType column value is the type of promotion you choose from the list of available Znode promotion types, the value of the class file name in the Promotion Engine library should match the ClassName column value.
- Then we need to add the attributes in the discount attribute mapper table (ZnodePromotionDiscountAttributeMapper) for the promotion created in the above step. For that, there are different types of attributes present in ZnodePromotionAttribute which has PromotionAttributeId also we can create a new attribute type by adding value in the table. The ZnodePromotionDiscountAttributeMapper table has the parameter PromotionAttributeId, which is the same PromotionAttributeId as the ZnodePromotionAttribute table.
After adding these data to the database you can observe that the created promotion is in the Discount Information tab → Discount type dropdown.
These are all the changes you need to make in the database to create a new promotion.
After adding the required data in the Znode database, the changes needed on the C# side are
- Custom Library: Create a custom library under the Libraries folder (For e.g.: Znode.Engine.Promotions.Custom) for implementing custom promotion classes
- Create a new “Custom Promotion Manager” class depending on the three types of promotions in Znode (eg: CustomZnodeCartPromotionManager.cs). This .cs file will inherit the Base class ZnodePromotionManager.cs and an IZnodePromotionManager interface. Add Reference to Znode.Engine.Promotion.
Cart Promotion Promotion is applied on the Shopping Cart page. Price Promotion Promotion is applied to the Price. Product Promotion
Promotion is applied to the Products.
- A Custom Promotion Helper class, we need a helper class in which we can have methods to get all promotion lists and promotion types also get promotions lists that are active on the current date, and more which will be needed for all the different custom promotions that are made.
- Custom Promotion specific class: We need a custom class for the type of promotion we choose (for eg: CustomPercentOffOrder). This will inherit the ZnodeCartPromotionType.
Note: The name of the Custom Promotion-specific class needs to be the same as the column value ClassName added in the database table ZnodePromotionType.
- All the custom logic related to creating and applying the promotion will go into this class and library.
- As per the scenario/requirement a custom controller can be created in the admin, API, and/or Webstore.
- If there is a requirement to introduce a custom model or a list model, this can be done in the Znode.Api.Model.Custom library.
- For inversion of control, in Znode.Api.Custom → DependencyRegistration.cs, we need to register the custom dependencies (if any).
- In the Custom PromotionManager, the methods of the base class ZnodePromotionManager can be overridden. For instance, Calculate, SetPromotionalPrice, CalculatePromotionDiscount, etc.
- In the custom helper class public methods can be overrode as well as introduced. For instance, GetPromotionList, GetPromotionShipping, and GetMostApplicablePromoList.
Note: If there are any private methods, then they need to be implemented separately in a separate region.
- References for Znode.Engine.Promotions. Customs need to be added in Znode.Api.Custom, Znode.Engine.Admin, Znode.Engine.Api.
- The new custom endpoints created need to be added to the CustomEnpoint.ts file.
- Optional Steps:
- Create a new Custom Promotion ts file, which will be required for all custom ts calls.
- We can create custom HTML views as per required by the custom promotion for Admin, API, and Webstore in Znode.Engine.Admin, API and Webstore Views.