Losing discounts when updating order in admin mode

Vote:
 

Hello, I am looking for some help on orderflows and promotion calculations, any help would be appreciated. 

When a user places an order successfully on our website, we set the order to AwaitingExchange. We then have a scheduled job that loops through orders with the AwaitingExchange status and sends them off to our company's internal order processor. There are a few things that could cause the order to be flagged, in which case we will not send the order and set the order to On Hold (a custom meta field). 

If an order is set to On Hold and the issue is resolved, then a Commerce Admin will go in and remove the hold flag. When this happens, we lose some discounts. Now, I found one thread with a very similar issue (https://world.optimizely.com/forum/developer-forum/Commerce/Thread-Container/2020/12/updating-order-address-causes-price-changes/) and the problem seems to be related to customizations which we definitely have. However, I can't seem to pinpoint what it is.

We have some code that runs when a promotion is applied to a cart which calculates the promotion and tax. I tried adding that code to run on IOrderEvents.SavingOrder. I verified that the event is fired and the code runs without exceptions. However, its not solving the issue. 

What do you guys think is going on?

#331192
Oct 09, 2024 22:37
Vote:
 

Hi,

I am not quite sure about your issue. As I understood then you have schedule job to send your AwaitExchange order to your internal system. If there is any exception when sending a certain order then you will flag that order as On Hold? Then commerce admin will go to Order Management and remove On Hold tag? Then the discounts were gone, right?

You added customized code to run promotion again once order is saved after this issue happens to try to fix the issue?

#331230
Oct 10, 2024 8:59
Vote:
 

what kind of discounts do you have? at the point of edit the promotion, were those expired?

it is now very hard to fix the problem in Commerce 13 (as it is no longer the latest), but might be the solution in Commerce 14 is to have a Save and Save without validation buttons for Admin UI ...

#331238
Oct 10, 2024 15:01
Vote:
 

Binh, thank you for your response. You are more or less correct. It is not necessarily all discounts that are gone. On my local system I have an order I can reproduce this issue on and the Line Item Discounts go from $16 to $4 after updating a meta field. 

I am able to track the process loosely and it is as follows:

  1. I view an order detail within commerce, the URL is like /episerver/Commerce/OrderManagement#/orders/<order-id>?tab=summary
  2. I update a metafield and in the network tab I see a request to the following URL: /episerver/Commerce/api///orders/<order-id>/metaFields
  3. From there, order saved events are fired
  4. When I refresh the page, the totals might be different

I would like to understand this process more in order to make sure this doesn't happen. As I said in my original post, I was trying to hook into the "Saving" event so I could run some code prior to the order saving but I haven't had success. I don't know if that is the best approach or not.

#331240
Oct 10, 2024 15:23
Vote:
 

Quan, these discounts are employee discounts so the discounts are definitely still active on production. I worry this may be the case for my local testing as my database may be older. However, for the actual live env, the discount is part of a campaign which does not expire until next year. The only thing is that there is a redemption limit of 12 for each employee but that number shouldn't get decremented on Validation, right?

As for bypassing validation, is it possible we could do that from the legacy commerce manager?

Lastly, is this something I can correct in an order saving event?

Thank you for the info about the upgrade, we have that planned for this year.

#331241
Oct 10, 2024 15:56
Vote:
 

We believe we have found the issue. It is not all of our discounts that are getting removed from the order. It is a specific discount that is only available to people in a specific visitor group that checks the email domain of the logged in user. It also checks that the current market currency is USD. 

I've crafted an admin user that fits that criteria but when updating the order we still get the same result. In addition, in my debugger the visitor group criterion are not even being evaluated, they only get evaluated when loading a CMS page. I think this is the cause of the issue, but how do we fix it?

#331245
Oct 10, 2024 19:57
Vote:
 

That will be a tricky one as VG is evaluated based on the current  http context. if the context is different the VG will not match.

I checked with the commerce development team and they said that the promotions will be reevaluated if the order status is In Progress. I will need to dig deeper to see if there is a way to customize that. but it wil be only applicable to Commerce 14 

#331295
Oct 11, 2024 15:15
Vote:
 

Yes, the discounts may be gone if discounts rely on email domain of current user. In commerce version 13, once we change meta field then order is validated again with validating line item, updating price changes, updating inventory changes, applying discounts again. 

@Zach Do you really want to run all order validation again like that once changing that meta field or you just want to change meta field value within ignoring order validation?

#331296
Oct 11, 2024 15:19
Vote:
 

@Binh, No we do not want to run all order validation again when updating a meta field. In this case, we would prefer everything stays the same, specifically pricing so that order totals are correct when we send the order over for processing. 

Is there a way to accomplish this?

Another thing, if the Commerce Admin (the one updating the meta field) was valid for the promotion as well, would this work? My breakpoints were not being hit in development so I could not verifiy this part. 

#331472
Edited, Oct 15, 2024 15:13
Vote:
 

Hi,

It is not reason if we try to have Commerce Admin with same visitor groups with all customers.

By defaut.order validation is always run again once you change meta field. I think you could customize for your case such as:

  • Creating new tool to update this meta field without order validation by your own instead of using default Order Management
  • OR using Order Status and updating Order Status instead of using meta field. You can use OnHold status when needing to resolve order again then update it back to InProgress to continue to send to external system

     

#331537
Edited, Oct 16, 2024 13:05
Vote:
 

@Binh, thank you for your response. I like both ideas. I am not sure why this site wasn't built that way originally. I supposed I might find out during development. However, both of these options are promising.

#331543
Oct 16, 2024 14:39
* 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.