Hide menu Last updated: Jul 14 2016

Promotion engine

This topic covers how the promotion engine in Episerver Commerce works, and how to use it for calculating discounts on a shopping cart.

Promotion engine flow

Calculate promotions 

Here is an example of how to use the new engine to calculate promotions using the new order API.

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

Get promotion prices

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

Evaluate entries

ServiceLocator.Current.GetInstance<IPromotionEngine>().Evaluate(entryLink);

Get promotions and items for campaign

ServiceLocator.Current.GetInstance<IPromotionEngine>().GetPromotionItemsForCampaign(campaignLink);

Calculate promotions using workflows

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

To use the new promotion system in the workflows, use one of these methods.

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

Comments