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

Recommended reading 

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);

Prices and rounding

In general, rounding occurs at every stage of the shopping process. Commerce ensures that fractions are distributed as evenly as possible to make the sums correct.

For example: buy 3 for $10. In this case, each line item (assuming three different products) gets $3.3333. But with rounding and "money sprinkling," the actual line item costs are $3.34, $3.33 and $3.33.

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

Last updated: Jul 14, 2016

Recommended reading