SaaS CMS has officially launched! Learn more now.

PromotionEngine.Evaluate always gives FulfillmentStatus.NotFulfilled on promotions (Commerce 10.4.3)


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 

_promotionEngine.Service.Evaluate(entry.ContentLink, _currentMarket.Service.GetCurrentMarket(), currency, RequestFulfillmentStatus.All);

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.

Edited, Oct 02, 2017 12:43

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? 

Oct 02, 2017 13:32

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.

Oct 02, 2017 15:16

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.

Oct 03, 2017 16:06

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.

Oct 03, 2017 16:25

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.

Oct 17, 2017 17:35

All "Buy at least X" should work as long as you define X=1 when you create the promotion.

Oct 18, 2017 14:36

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:

  • Most Expensive Items For Free
  • Buy Products for Discount on All Selections

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.

Oct 20, 2017 9:51

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.

Oct 20, 2017 10:28
* 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.