In the new [BETA] Marketing section is is possible to evaluate promotions to an order or cart (IOrderGroup)
But in the product detail page of our new store we want to display the discounted price for a promotion (if a valid promotion exists)
Is there functionality planned for the PromotionEngine to Evaluate promotions on a Collection or Single instance of a Entry?
Yes, that's what we are working on the upcoming version of Commerce - I would expect it to be released in 1-2 weeks (just don't take my words as promises :) )
Yes, such a functionality available shortly. You will be able to evaluate either a single or a collection of ContentReferences referencing an entry. Those API:s should be included in the next Commerce release.
Than I will not start Developing this myself. ;)
Thanks for the quick response!
There is now a release out that contains this API, http://world.episerver.com/releases/episerver---update-112/. If you give it a try, we welcome any feedback for use cases we might have missed, or that could be handled better.
I've been working with this and most of it seems to work great.
I just have one problem. When I target a Campaign to a VisitorGroup, and I run the Evaluate function on the promotionEngine, I get an exception.
Object reference not set to an instance of an object at EPiServer.Commerce.Marketing.CampaignVisitorGroupFilter.IsInVisitorGroup
This seems to happen because HttpContextBase is null.
In the 'workflows' when added the product to the Cart it all works.
The visitor group filtering does require an http context, since many of the criteria uses it to evaluate if they match or not. However, if no http context exists, it should not fail with a null reference exception. That is a bug, and I'll register that in our systems.
I wonder, where are you calling these methods from? Is it from somewhere where no http context would exists?
Thanks for the report.
I was handling my searchresults Asynchronously, so the code to get the price for the products was called from another thread.
Right, that makes sense.
We'll fix this by simply ignoring any visitor group checks of campaigns/promotions if there is no http context available. In other words, if the check is run in a scenario where there is no http context, no promotions will be skipped because of the current user not belonging to any of the required visitor groups.
We have met the issue from a partner that if there's no HttpContext then it should be assumed that no visitor groups match and those campaigns should be excluded. So the behavior of above scenario has changes. Now, we'll excluded all campaigns/promotions if there is no http context available.