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 

This topic describes how to create a volume discount promotion. This discount has only a MinOrderAmount custom variable, which qualifies or disqualifies the discount.

The implementation consists of the following steps:

  1. Create the expression rules.
  2. Create and test the user interface for administering the volume discount.
  3. Create unit tests for testing the promotion.
  4. Test the promotion.

Classes in this topic are available in the following namespaces:

See also Promotions and Custom Promotion Development.

Step 1: Create the expression rules

The result of this step is an XML document used by the back-end to create the actual discount record.

The XML Rule Set should consist of these rules:

  • SetupConstants. Sets up a constant in the current runtime context that the rules engine can use. The constant name should be $MinOrderAmount.
  • CheckOrderSubTotal. Validates current order subtotal and compares it to the constant specified. Use the SourceEntriesSet.TotalCost property instead of Cart.SubTotal.
  • AssignReward. Adds a new PromotionItemRecord with a reward of type WholeOrder.

Note: 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: Create the administrative UI

The result of this step is a screen that lets the store administrator create a new Volume Type discount.

  1. Create new file Apps\Marketing\Promotions\Configs\OrderVolumeDiscount.config. 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 PairedPromotion discount 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: Create unit tests

The result of this step is a set of unit tests that validate that the promotion engine and specific discount work 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(). 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. If this is not fulfilled, it should throw an exception.

Step 4: Test 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. The total volume discount promotion appears.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Oct 12, 2015

Recommended reading