Loading...
Area: Episerver Commerce
Applies to versions: 10 and higher
Other versions:

Promotion engine

Recommendations [hide]

This topic covers how the Episerver Commerce promotion engine works, and how it is used when calculating discounts on a shopping cart. 

Promotion engine flow

promotion engine - COM13.PNG

   

Calculating promotions

Components mentioned here are available in the EPiServer.Commerce.Marketing namespace. PromotionEngine evaluates the condition on all active promotions and gives reward to specific orders when the conditions are fulfilled.

Here is an example of using the promotion engine to calculate promotions using the order API.

var cart = ServiceLocator.Current.GetInstance<IOrderRepository>().LoadOrCreateCart<Cart>(PrincipalInfo.CurrentPrincipal.GetContactId(), Cart.DefaultName);
IEnumerable<RewardDescription> rewardDescriptions = ServiceLocator.Current.GetInstance<IPromotionEngine>().Run(cart);

Getting promotion prices

var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
IEnumerable<DiscountedEntry> discountedEntries = promotionEngine.GetDiscountPrices(entryLink, currentMarket);

You can also get promotion prices for a collection of entries.

var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
var market = currentMarket.GetCurrentMarket();
IEnumerable<DiscountedEntry> discountedEntries = promotionEngine.GetDiscountPrices(entryLinks, market, market.DefaultCurrency);

Evaluating entries

Evaluate a single entry.

IEnumerable<RewardDescription> rewardDescriptions = ServiceLocator.Current.GetInstance<IPromotionEngine>().Evaluate(entryLink);

Evaluate a collection of entries.

IEnumerable<RewardDescription> rewardDescriptions = ServiceLocator.Current.GetInstance<IPromotionEngine>().Evaluate(entryLinks);

Getting promotions and items for campaign

IEnumerable<PromotionsItems> promotionItemsList = ServiceLocator.Current.GetInstance<IPromotionEngine>().GetPromotionItemsForCampaign(campaignLink);

Calculating promotions using workflows

You can run the promotion system with the workflow system (legacy) to calculate and remove promotions. Updated workflow activities use the EPiServer.Commerce.Marketing.IPromotionEngine to make calculations and manipulate the cart.

The new promotion system is used by default in the workflows. Use one of these methods to disable it.

  • Update Configs\ecf.app.config.
    <Application defaultApplicationName="ECApplication">
      <Features>
        <add feature="WorkflowsVNext" state="Disabled" type="Mediachase.Commerce.Core.Features.WorkflowsVNext, Mediachase.Commerce" />
      </Features>
    </Application>
  • Use the Servicelocator.
    var featureSwitch = ServiceLocator.Current.GetInstance<IFeatureSwitch>();
    featureSwitch.Features.Add(new WorkflowsVNext());
    featureSwitch.DisableFeature(WorkflowsVNext.FeatureWorkflowsVNext);

Related topics

Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 25, 2019

Recommendations [hide]