Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Duplicate Line Item gets added on Applying discount

Vote:
 

Extension Method in EPiServer.Commerce.Order.IOrderGroupExtensions

ApplyDiscounts(this IOrderGroup orderGroup, IPromotionEngine promotionEngine, PromotionEngineSettings settings);

When this method is called on order object it is adding duplicate line item and removing the other line items. This is the case only when If you have created a Discount/Promotion and has Product in the `This discount does not apply to these catalog items` list. Then if you have that product addedf in cart along with other products in that case above specified method add's duplicate line item.

Example:- Suppose you have Product A in excluded list and Product A and Product B in cart then on Applying discount you will have two products and both will be Product A.

Because of this we are getting an exception of duplicate line item. I guess it should not have added duplicacy and either provide error or apply discount only to Product B as per example case.

#284519
Jul 27, 2022 12:03
Vote:
 

Hi Sandeep,

What are the details of the promotion being applied?

#284736
Aug 01, 2022 8:17
Vote:
 

Hello Sandeep, 
Have you customized promotion that you are applying? Couple of things to check - 
1. You don't have multiple promotions active for the same item and same amount if any threshold is limited. This will conflict and not a valid case.
2. Check for promotion processor if you have it customized. 


#284751
Aug 01, 2022 12:17
Vote:
 

Hi Surjit and Manoj,
First of all thanks for your response.
I have created a Campaign and in that have two discounts
   1. Item Discount (20% off) : 20% off on particular category items, it is applied automatically
   2. Order Discount (Spend100) : 10% discount on spend of 100, it is applied with promotion code

I have not customized promotion and there's no limits set.

#284813
Aug 02, 2022 10:07
- Aug 04, 2022 11:09
Just a wild guess if you can swap the priorities of both the promotions if that makes any differences?
Sandeep Singh Shekhawat - Aug 29, 2022 11:47
Hi Manoj, although I have not set priorities explicitly but even when there's only one discount in Campaign it works the same.
- Aug 29, 2022 13:05
Sandeep, Can you check with Foundation solution whether configuring same promotion behaves the same? Can you also try updating commerce if that helps. I think if the error is reoccurring in foundation solution then this is a bug with the version you are using.
- May 24, 2023 7:23
I have checked my code and compared it with Foundation solution they are almost same and there's no error in Foundation.
I narrowed down further and found that this error is thrown when _orderValidationService.ValidateOrder method is called and product item which is excluded from promotion is also in cart. Also this kind of error can be seen for other cases too which was there when culture specific field is set to non culture specific kind.
Attaching error screenshot below.
Vote:
 

Here is the screenshot of the exception

#302267
May 24, 2023 7:24
Vote:
 

Hi Sandeep,

It is very difficult to understand the flow of you application. However I have seen behaviour simialr to this before. Here are some things to check.

  1. Custom Shipping Gateway - We had a custom shipping gateway that would give free shipping over a certain amount. When applying promotions this caused issues as it was not in priorty list. Essientially rework this code so discounts are not applied via shipping gateway. This was also raised as a bug with Optimizely.
  2. ApplyDiscount calls a number of additional services, placedpriceprocessor, promotionengine, validation, etc. You may be calling validate order unnessarily, or one of these other services is causing the duplication.

Hopefully that helps with you investigation. If you are really stuck I would reach out to Optimizely support who will be able to assit further. It is always useful if you have a demo they can refer to so try to set something up and explain the steps to reproduce.

Thanks

Paul

#302273
May 24, 2023 8:59
* 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.