Extending Promotion Engine in Znode


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 Promotion

Cart promotions apply discounts to customers' carts.

Price Promotion

Promotions are applied to the price.

Product Promotion 

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. 

  1. 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.
  2. 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

Database Changes

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

  1. 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.
  2. 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. 

Code/SDK changes

After adding the required data in the Znode database, the changes needed on the C# side are

  1. Custom Library: Create a custom library under the Libraries folder (For e.g.: Znode.Engine.Promotions.Custom) for implementing custom promotion classes
  2. 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.

  3. 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. 
  4. 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.
  5. All the custom logic related to creating and applying the promotion will go into this class and library.
  6. As per the scenario/requirement a custom controller can be created in the admin, API, and/or Webstore. 
  7. 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.
  8. For inversion of control, in Znode.Api.Custom → DependencyRegistration.cs, we need to register the custom dependencies (if any).
  9. In the Custom PromotionManager, the methods of the base class ZnodePromotionManager can be overridden. For instance, Calculate, SetPromotionalPrice, CalculatePromotionDiscount, etc. 
  10. 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.
  11. References for Znode.Engine.Promotions. Customs need to be added in Znode.Api.Custom, Znode.Engine.Admin, Znode.Engine.Api. 
  12. The new custom endpoints created need to be added to the CustomEnpoint.ts file.
  13. Optional Steps: 
    1. Create a new Custom Promotion ts file, which will be required for all custom ts calls.
    2. 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.

Did you find it helpful? Yes No

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