Get if entry is part of a campaign/promotion?


How can I get a promotion for a specific entry? For example, displaying the promotion on a productdetails page.

I have found this.

var promotionEngine = ServiceLocator.Current.GetInstance();
var currentMarket = ServiceLocator.Current.GetInstance();
promotionEngine.GetDiscountPrices(entryLink, currentMarket);

But I would like to get the entire discount/campaign that the entry is in. And I mean, this if for display only. When we list products, show if the article is part of the campaign/promotion. This is not to be able to evaluate the promotion or not.

So really, just wan't to show if the entry is part of a campaign/promotion.


Edited, Mar 14, 2017 12:59

GetDiscountPrices returns a list of DiscountedEntry, which each of them contains a list of DiscountPrice. Each discount price has an EntryPromotion property. So if you do something like this:

var discountPrices = promotionEngine.GetDiscountPrices(entryLink, currentMarket);

var promotions = discountPrices.SelectMany(c=>c.DiscountPrice.Promotion);

you'll be able to get the list of promotions applied to that entry.

Mar 14, 2017 13:47

I ended up using the evaluate method of promotionengine instead (sending in currentMarket, currency and RequestFulfillmentStatus). Thanks for the answer though!


Mar 14, 2017 14:35

The IPromotionEngine.Evaluate method is the recommended approach, it was added to solve this precise use case.

Mar 14, 2017 15:43

GetDiscountPrices is the shorter way to go because with Evaluate you will have to create an IOrderGroup instance, add the form and lineitem etc. then past it to PromotionProcessorContext. GetDiscountPrices does all those things for you internally.

Mar 14, 2017 15:51

You mean IPromotionEngine.Evaluate creates an IOrderGroup instance internally?

We are talking about the Evaluate method and not the Run method(which takes an IOrderGroup)?

GetDiscountPrices itself calls the Evaluate method internally and unless you actually want to know the discounted price there is no need to use it and waste all that extra computation.

Furthermore to the point GetDiscountPrices hides the RequestFulfillmentStatus and will only work with RequestFulfillmentStatus.Fulfilled and for this use case you typically wants to include RequestFulfillmentStatus.PartiallyFulfilled also.

Mar 14, 2017 17:08

OK I mixed thing up. Yes, IPromotionEngine.Evaluate creates an IOrderGroup instance internally (which I mixed with Run), and yes GetDiscountPrices uses Evalute internally. So my statement above is incorrect - Evaluate should be the shorter way to go. 

Edited, Mar 14, 2017 17:17

Btw, how I solved it.

var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var promotions = promotionEngine.Evaluate(content.ContentLink,
                          RequestFulfillmentStatus.Fulfilled |
Mar 16, 2017 8:38
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.