Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Introduction

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:

  1. Creating the expression rules.
  2. Creating and testing the user interface for administering the volume discount.
  3. Creating unit tests for testing the promotion.
  4. Testing the promotion.

Classes referred to here are available in the following namespaces:

Refer also to Promotions and Custom Promotion Development for related information.

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:

  1. 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".
  2. CheckOrderSubTotal. This will validate current order subtotal and compare it to the constant specified. Use the SourceEntriesSet .TotalCost property instead of Cart.SubTotal.
  3. AssignReward. This will add new PromotionItemRecord with a reward of type "WholeOrder".
The rule should be executed only once against the full order. Compare this to a line item type of discount where a rule is executed for each line item in the order.

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.

  1. Create 3 promotions with a MinOrderAmount of "1000", "2000" and "3000". They will give the discounts 5%, 10% and 15%.
  2. Create a new class CommerceLibTest\MarketingSystem\MarketingSystem_OrderVolumePromotion.cs.
  3. Create a new method MarketingSystem_OrderVolumePromotion_10PercentOff().
  4. This method should create a new SourceEntriesSet and TargetEntriesSet with an items Total amount equal to 2000.
  5. 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

  1. Go to the front-end website and add products so that the total adds up to more than 1000.
  2. Go to the shopping cart.
  3. You should now see the total volume discount promotion.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 21, 2014

Recommended reading