Try our conversational search powered by Generative AI!

Remove OrderPromotion type from a saved PurchaseOrder before an update to the LineItems and Totals


Commerce Version 11.2.1
CMS Version 10.10.4

We've come across an issue that once a PurchaseOrder has been created, should any changes get made to the LineItems prior to a payment capture, on Save of the PO to then ProcessPayments, the PO re-runs the Promotions and changes the expected Totals.

To give some background on what is happening:

Order Created

  1. A Successful order is placed and the PurchaseOrder is created and saved (After successful Authorization to Payment Provider)
  2. A service call is made to push an XML representation of the PO out to an external ERP system
    1. The XML contains the LineItems prices which has all discounts wrapped up into them, we pass no separate discount line info (by design of External ERP)

Order is updated - this occurs when ERP notifies of order shipping and will include updates

  1. XML message pushed to API endpoint for OrderUpdates
  2. OrderUpdate received containing 1 less line item and updated TaxTotal, LineTotal and OrderTotal
  3. PurchaseOrder opened, line items and costs are updated
  4. Purchase Order is saved
  5. Payments are processed
    1. At this point, payment has been updated ready to process Capture in the PaymentGateway

If the PurchaseOrder originally had an OrderPromotion applied to it (automatic, no coupon code needed), when we save the PO in step 4 above, the Order Promotion will be re-run.  As we've updated the prices, the 20% order discount that exists gets executed a 2nd time and therefore we end up with a lower Capture amount.

I want to somehow disable all Promotions that may exist against the PO.

I've tried the following:

Removing the Promotions

  • po.GetFirstForm().Promotions.Clear()
  • promotionProcessor.Run(po)

    perhaps the OrderPromotion gets reapplied because the Order still fits the criteria?

Temporarily exclude the Entry items

  • Using IEntryFilter and setting the items of the PO to be excluded
  • Remove the filter after

    This seemed to prevent the OrderPromotion being re-added, but it still has the previous order discount total being applied.

I've tried other combinations with PromotionInformation / PromotionData objects that are in the Promotions collection, but this doesn't seem to have much affect.

Any tips out there.?



Edited, Nov 01, 2017 15:23


Regardless if the promotion engine is run or not, wont the ERP update that contained 1 less line item change the price for the order? Or if it changes the shipping fee, you still have the base problem that the cost for the user changed behind the scenes.

Generally I think your problem is that you are running your promotions on purchase orders. I don't see a scenario where you would want to evaluate all the promotions against a created purchase order. When the user clicks on the final "buy" button, you convert the cart to a purchase order. And promotions have already been applied to the cart (given that you run promotions), so the applied promotions are still in the purchaseorder.

Am I sort of making sense in your case or have I misunderstood stomething?

Nov 02, 2017 10:10

Hi Joel,

Yes, the ERP update changes the total order cost, but the update provides the Tax / Shipping / Order Total costs which then get rewritten to the  PO.  At this point, the user has already bought the order, so we know longer are using Cart, but a PO.

The issue is that when we update the values and save the PO, the Order Promotion is running again and reducing the total order cost, changing it from what ERP provided.  This then means the amount we Capture is different to what the PO should be.  I'm also not actually running the Promotion processor, it just appears to be running on save.

So I'm trying to understand why it re-applies this promotion and how to prevent it.

Edited, Nov 02, 2017 13:17

Do you use any workflow when the ERP calls your server with updated order information?

Nov 02, 2017 14:01

I'm not specifically calling any, the update happens on _orderRepository.Save(po)

After that, we then do po.ProcessPayments()

Nov 03, 2017 10:23

orderRepository.Save shouldn't run the promotions. It will calculate the totals however, but not run promotions. Hm. You sure you don't have any code in that path that in turn runs promotions?

Nov 03, 2017 10:56
* 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.