Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Exclude promotions

Describes how to prevent promotions from being combined with other promotions in Optimizely Commerce Connect.

Determine which promotions cannot be combined with others. For example, while running a 20% off automotive supplies sale, customers should not be able to combine the promotion with a Get cheapest item 50% off promotion on the same item.

Classes in this topic are available in the following namespace:

  • EPiServer.Commerce.Marketing

Use order-level and unit-level exclusions

The Commerce Connect API supports both order-level and unit (item)-level exclusions.

Set the desired action through the ExclusionLevel property on the PromotionEngineSettings passed when running the PromotionEngine. The following examples use exclusion levels with the PromotionEngine.

Call the PromotionEngine directly:

var cart = ServiceLocator.Current.GetInstance<IOrderRepository>().LoadOrCreateCart<Cart>(PrincipalInfo.CurrentPrincipal.GetContactId(), Cart.DefaultName);
    ServiceLocator.Current.GetInstance<IPromotionEngine>().Run(cart, new PromotionEngineSettings() { ExclusionLevel = ExclusionLevel.Unit }));

Use the ApplyDiscounts extension method:

var cart = ServiceLocator.Current.GetInstance<IOrderRepository>().LoadOrCreateCart<ICart>(PrincipalInfo.CurrentPrincipal.GetContactId(), Cart.DefaultName);
    cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings() { ExclusionLevel = ExclusionLevel.Unit });

For another sample implementation, see the Optimizely QuickSilver sample site, in the CartService class.

Order-level exclusion

ExclusionLevel.Order, the default setting, ensures that two promotions excluding each other are not applied within the same OrderGroup. If both are applied, the higher-priority promotion is used, while the other promotion is ignored.

To exclude promotions, set a list of ContentReference to the ExcludedItems property of the PromotionData. The following samples illustrate this.

promotionData.ExcludedItems.Add(campaignLink);
promotionData.ExcludedItems.Add(anotherPromotionLink);

You can add the following types of ContentReference to the ExcludedItems property:

  • The SalesCampaign.CampaignRoot – This promotion cannot be combined with any other promotions.
  • A campaign's ContentLink – This promotion cannot be combined with any promotions in that campaign.
  • A promotion's ContentLink – This promotion cannot be combined with that specific promotion.

Unit-level exclusion

Use ExclusionLevel.Unit with promotions whose DiscountType value is LineItem.

📘

Note

If you use ExclusionLevel.Unit with any promotion type other than LineItem, its behavior is the same as ExclusionLevel.Order.

Unit-level exclusion means that two promotions that exclude each other are both applied in an OrderGroup.

As with Orders, you exclude promotions by adding ContentReferences to the ExcludedItems list.

promotionData.ExcludedItems.Add(campaignLink);
promotionData.ExcludedItems.Add(anotherPromotionLink);

For example:

Preconditions:

  • Promotion P1 is "Buy 3 of product A and get a 10% discount on 1 product A".
  • Promotion P2 is "Get 5% off product A".
  • P1 has a higher priority than P2.
  • An order group has the following line item: SKU = A, quantity = 10.

If either P1 or P2 excludes the other:

  • P1 gives one unit a 10% discount.
  • The two other units used in the P1 promotion are charged full price.
  • The remaining seven units are available for P2, each receiving a 5% discount.
📘

Note

The sequence in which promotions are executed is determined by their priority.