Updating an order

When an order is placed in Sitecore commerce, the order goes to pending status. From pending status, an order can either be released or put on hold. OnHold is an interesting status in Sitecore Commerce. You can make changes to the order while it is on-hold.

If you come across a requirement of making changes to an order after it is placed, On-hold status is your best buddy. I had to implement, order updates. The updates were supposed to come from an external system. This is how I approached the whole solution.

  1. Pending order minion updates the order status to OnHold after the order goes to that external system.
  2. A new Ops API exposed to the external system(the api works just like any other api and expects an auth token).
  3. An order update pipeline which updates the order entity.

I will mainly share the details of that pipeline here but before I go to the details of that pipeline, I just want to highlight the main steps you need to do achieve this.



  1. GetOrderCommand: Gives you the order entity based on the order Id that you get as input.
  2. GetOnHoldOrderCartCommand: This command gives you a temporary cart to be able to update all the information. When an order is put on hold, SXC attaches a temporary cart with the order entity. This cart contains all the information for that order.
  3.  Delete un-matching lines: If some lines were deleted from original order, we will delete them from the cart.
  4. Update matching lines: The lines we receive in the input model, would be updated in the cart.
  5. ReleaseOnHoldOrderCommand: This command converts the temporary cart to order and replaces the actual order.
  6. Release Order: An optional step, if we want to say, our order is now released.

Exploring the Pipeline:

  1. GetOnHoldOrderBlock: This block simply gets the order entity using GetOrderCommand and puts it in the args.
  2. GetTemporaryCartBlock: This block uses GetOnHoldOrderCartCommand to get the temporary cart from the order and puts the temporary cart in the args.
  3.  DeleteMissingOrderLinesBlock: This block deletes the order lines which are not valid anymore.
  4. UpdateOrderLinesBlock: This block updates the line quantity and other information.

  5. SaveOrderBlock: This block runs IPersistEntityPipeline to save the changes to the order entity.
  6. ReleaseOrderBlock: This block is responsible for converting the updated cart to the order and move it to Release status. It uses ReleaseOnHoldOrderCommand which is responsible for converting the temp cart to order and MovePendingOrderToReleasedCommand which then moves the order to Released.

Happy Sitecorians!

Leave a Reply

Your email address will not be published. Required fields are marked *