November Happy Hour will be moved to Thursday December 5th.

Evaluate Promotions Fail for Redemption Limits

Vote:
 

Hi there!

I recently migrated to the latest Commerce 14 version and an error started when applying for promotions using the Redemption Limits rules. If there is a value greater than zero in the Per registered user field, the promotion is never applied. It only works for unlimited redemptions.

The following image shows the configuration for a limited promotion:

This is part of the code I am using for evaluating promotions:

var inMemoryOrderGroup = new InMemoryOrderGroup(currentMarket, currencyCode);
inMemoryOrderGroup.OrderLink = cart.OrderLink;

foreach (ILineItem lineItem in cart.GetFirstForm().GetAllLineItems())
{
	inMemoryOrderGroup.AddLineItem(lineItem);
}

inMemoryOrderGroup.GetFirstForm().CouponCodes.Add(couponCode);

rewards = ServiceLocator.Current.GetInstance<IPromotionEngine>().Run(inMemoryOrderGroup);

if (rewards.Any())
{
	// rewards is empty
}

Is there something else I need to consider in the new Commerce 14 version to evaluate promotions? (The same code was working in version 12.15)

#300643
Apr 24, 2023 13:38
Vote:
 

Is this current customer logged in? Also how do you create "inMemoryOrderGroup" ?

#300688
Apr 25, 2023 9:24
Vote:
 

Yes, it is the current customer who logged in.

The `InMemoryOrderGroup` is created using the current market (`ServiceLocator.Current.GetInstance<ICurrentMarket>().GetCurrentMarket()`) and current currency code (`ServiceLocator.Current.GetInstance<ICurrencyService>().GetCurrentCurrency().CurrencyCode`) then I add lines using the `AddLineItem` method.

#300694
Apr 25, 2023 13:26
Vote:
 

What's about the CustomerId of the InMemoryOrderGroup?

#300695
Apr 25, 2023 13:30
Vote:
 

Hi Quan,

Thank you for your help. I set the CustomerId value in the InMemoryOrderGroup object and worked! This is the new code:

var inMemoryOrderGroup = new InMemoryOrderGroup(currentMarket, currencyCode);
inMemoryOrderGroup.OrderLink = cart.OrderLink;
inMemoryOrderGroup.CustomerId = cart.CustomerId;

foreach (ILineItem lineItem in cart.GetFirstForm().GetAllLineItems())
{
	inMemoryOrderGroup.AddLineItem(lineItem);
}

inMemoryOrderGroup.GetFirstForm().CouponCodes.Add(couponCode);

rewards = ServiceLocator.Current.GetInstance<IPromotionEngine>().Run(inMemoryOrderGroup);

if (rewards.Any())
{
	// rewards contain elements
}
#300839
Apr 27, 2023 16:21
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.