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();
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.
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.
I ended up using the evaluate method of promotionengine instead (sending in currentMarket, currency and RequestFulfillmentStatus). Thanks for the answer though!
The IPromotionEngine.Evaluate method is the recommended approach, it was added to solve this precise use case.
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.
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.
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.
Btw, how I solved it.
var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var promotions = promotionEngine.Evaluate(content.ContentLink,