Which promotions do you have, and what are their conditions? Did it work if you add just one lineitem (with quantity = 1) into the cart?
Also perhaps some dummy check list questions: Is the market the same as in the cart? Currency the same?
In the end they fall to the same method, difference being Evaluate will create a in memory cart with just the one lineitem with quantity = 1 and run promotions on that, if I remember correctly.
The promotion I'm trying to use is "Buy products for discount in same category", and yes, it works with quantity = 1 in the cart.
I've checked, and the market is "Default Market" (id = DEFAULT) for both the cart and for calls to the PromotionEngine. The currency is also the same. This particular site only has one market and one currency in play anyway.
I'm as baffled as anyone why this isn't working, but it's certainly problematic, since our customer wants to be able to display the promotions that apply to a product.
Does any other promotion work for you?
Specifically test to see if it is the resolution of the lineitem's category that might be the issue.
None of the built-in promotions seem to have this possiblity. They're either of the type "Buy at least X" or they involve categories or another item than the one in question in some way or another.
All "Buy at least X" should work as long as you define X=1 when you create the promotion.
As I said, all the "Buy at least X" that I can see all require you to set a category that the promotion should apply to. There are two of them, and both require that you set a category:
Anyway, I got tired of this not working, so I figured I'd give a go at getting it to work on my own. To my amazement, this simple bit of code works just fine:
var promoCart = _cartService.Service.LoadOrCreateCart("PromotionTest"); _cartServiceExtended.Service.AddToCart(promoCart, selectedVariant.Code, out var _, false); var lineItem = promoCart.GetAllLineItems().First(); var rewards = _promotionEngine.Service.Run(promoCart); var dDP = lineItem.GetDiscountedPrice(currency); var xDP = lineItem.GetExtendedPrice(currency); var pDP = lineItem.PlacedPrice;
Here, "rewards" contains my expected reward, with Fulfillmentstatus.Fulfilled, and GetDiscountedPrice()/GetExtendedPrice() give expected values. While not ideal, I'm just going to go ahead with this code, because _promotionEngine.Evaluate() just doesn't work, unlike _promotionEngine.Run(), which clearly does.
They don't require you to set a category, they require you to set a content, for example the entry you are actually trying to get a discount for.
I have no idea what _cartService you are using but as long as you use the InMemory classes you should be fine.
The promotion system works just fine in the cart/checkout calculations (i.e. promotions/discounts are correctly applied to lineitems in a cart), but when I'm trying to evaluate a single product or variant for promotions on the product page, using
then all the returned RewardDescriptions have their Status set to FulfillmentStatus.NotFulfilled. (I'm only using that method signature because the default one returned 0 results, which makes sense, considering that it thinks none of the rewards apply.)
Do I have to do something more than just calling Evaluate() to get this to work?
EDIT: GetDiscountPrices() also returns 0 results, again despite it working as expected in the cart.