This document provides an overview of the steps to create a volume discount promotion. This particular discount will only have one custom variable called "MinOrderAmount", which will be used to qualify or disqualify the discount.
The implementation consists of the following steps:
- Creating the expression rules.
- Creating and testing the user interface for administering the volume discount.
- Creating unit tests for testing the promotion.
- Testing the promotion.
Classes referred to here are available in the following namespaces:
Step 1: creating the rules
The result of this step will be an XML document used by the back-end to create the actual discount record.
The XML Rule Set should consist of these rules:
- SetupConstants. This will setup a constant in the current runtime context that can be used by the rules engine. The constant name should be "$MinOrderAmount".
- CheckOrderSubTotal. This will validate current order subtotal and compare it to the constant specified. Use the SourceEntriesSet .TotalCost property instead of Cart.SubTotal.
- AssignReward. This will add new PromotionItemRecord with a reward of type "WholeOrder".
Step 2: creating the administrative UI
The result of this step will be a screen that will allow the store administrator to create new Volume Type discount.
1. Create a new "OrderVolumeDiscount.config" file under "Apps\Marketing\Promotions\Configs" directory. Specify the following parameters:
- Type: "OrderVolumeDiscount"
- Name: "Order Sub Total Volume Discount"
- Description: "This type of promotion discounts the order subtotal if minimum order amount is met"
- Group: "order"
- Path: "OrderVolumeDiscount\ConfigControl.ascx"
- Expression: enter the expression generated in Step 1.
2. Create new file "Apps\Marketing\Promotions\OrderVolumeDiscount\ConfigControl.ascx". You can use the other discount "PairedPromotion" as a template.
The UI should include two fields:
- Min. Order Amount
- Amount (exists in PairedPromotion)
3. Modify the Settings class to include MinOrderAmount and remove unused properties.
4. Test the administration user interface.
Step 3: creating unit tests
The result of this step will be a set of unit tests that validate that the promotion engine and specific discount works correctly.
- Create 3 promotions with a MinOrderAmount of "1000", "2000" and "3000". They will give the discounts 5%, 10% and 15%.
- Create a new class CommerceLibTest\MarketingSystem\MarketingSystem_OrderVolumePromotion.cs.
- Create a new method MarketingSystem_OrderVolumePromotion_10PercentOff().
- This method should create a new SourceEntriesSet and TargetEntriesSet with an items Total amount equal to 2000.
- The method should execute the promotion engine and check the reward. It should equal to 200, and if this is not fulfilled it should throw an exception.
Step 4: testing the promotion
- Go to the front-end website and add products so that the total adds up to more than 1000.
- Go to the shopping cart.
- You should now see the total volume discount promotion.