Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
This topic covers how the promotion engine in Episerver Commerce works, and how to use it for calculating discounts on a shopping cart.
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);
var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var currentMarket = ServiceLocator.Current.GetInstance<ICurrentMarket>();
promotionEngine.GetDiscountPrices(entryLink, currentMarket);
ServiceLocator.Current.GetInstance<IPromotionEngine>().Evaluate(entryLink);
ServiceLocator.Current.GetInstance<IPromotionEngine>().GetPromotionItemsForCampaign(campaignLink);
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.
<Application defaultApplicationName="ECApplication">
<Features>
<add feature="WorkflowsVNext" state="Enabled" type="Mediachase.Commerce.Core.Features.WorkflowsVNext, Mediachase.Commerce" />
</Features>
</Application>
var featureSwitch = ServiceLocator.Current.GetInstance<IFeatureSwitch>();
featureSwitch.Features.Add(new WorkflowsVNext());
featureSwitch.EnableFeature(WorkflowsVNext. FeatureWorkflowsVNext);
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.
Last updated: Jul 14, 2016