Post submission updates on sitecore commerce orders

In this blog post, I will talk about how to make updates to an order that is already submitted in the system. Imagine a scenario where the customer has placed an order via web and calls the customer rep to apply payment or add more details. How do we accomplish this?

There are cases where we have to make changes on an order after it has already been processed. Let me walk you through the process and show how to make updates on an existing order.

  • Make sure you order is in a status from where it can be put on hold. Looking at the environment json, the onHoldOrderPolicy has OOTB Pending and Problem statuses. It means that if your order is in pending or in problem status then only you can put it on hold and make changes. You can easily override and add your custom statuses.
        "$type": "Sitecore.Commerce.Plugin.Orders.OnHoldOrdersPolicy, Sitecore.Commerce.Plugin.Orders",
          "$type": "System.Collections.Generic.List1[[System.String, mscorlib]], mscorlib",
          "$values": [ "Pending",  "Problem" ]
  • You can use ISetOrderStatusPipeline to set the order status to Pending before putting the order on hold, if required
  • Put the order on hold, call the pipeline IHoldOrderPipeline. It accepts an order id and context
  • Then get the temporary cart by calling the GetOnHoldOrderCartCommand  (var tempCart = await _getOnHoldOrderCartCommand.Process(commerceContext, order);)
  • Make changes on the temp Cart (Add a component or apply payment)
  • Persist the temp cart if you are not using pipelines that already persist (var cart = (await _persistEntityPipeline.Run(new PersistEntityArgument(tempCart), context)).Entity as Cart;)
  • Release the order using IReleaseOnHoldOrderPipeline

When an order is moved to onHold status, an OnHoldComponent is added to the order and a temporary cart is created. The changes you make are made on the temp cart. During the release of order, if the validations fails (like order totals do not match), the temp Cart still lives in the database. You can query it using postman get cart api by the guide present in the onHoldComponent of the order to see what is wrong. Also, when the order is successfully released, the temp Cart is deleted and onHoldComponent is removed from the order.The order is finally moved to pending status again.

This is such a nice streamlined process. 

To read more of XCentium's Sitecore Experience Commerce blogs, please click here.