Try our conversational search powered by Generative AI!

Get if entry is part of a campaign/promotion?

Vote:
 

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.

//T

#176246
Edited, Mar 14, 2017 12:59
Vote:
 

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.

#176249
Mar 14, 2017 13:47
Vote:
 

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

//T

#176252
Mar 14, 2017 14:35
Vote:
 

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

#176260
Mar 14, 2017 15:43
Vote:
 

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.

#176264
Mar 14, 2017 15:51
Vote:
 

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.

#176274
Mar 14, 2017 17:08
Vote:
 

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. 

#176275
Edited, Mar 14, 2017 17:17
Vote:
 

Btw, how I solved it.

var promotionEngine = ServiceLocator.Current.GetInstance<IPromotionEngine>();
var promotions = promotionEngine.Evaluate(content.ContentLink,
                          _marketLocator.GetMarketByCulture(content.Language),
                          _marketLocator.GetMarketByCulture(content.Language).DefaultCurrency,
                          RequestFulfillmentStatus.Fulfilled |
                          RequestFulfillmentStatus.PartiallyFulfilled).ToList();
#176324
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.