Sitecore Experience Commerce: Order Lists And How To Manage them


Out of the box, Sitecore Experience Commerce has a configured minion running in the background from the minions environment which is responsible for moving the orders from the initial status of the Order i.e., Pending to final stage, i.e., Completed. By the end of this article, I will walk you that process which will help you understand how we can move orders between lists and how to remove an order from a list.

To get an understanding on how the orders move between these lists, let’s deep dive by taking one of the minions as an example, Sitecore.Commerce.Plugin.Orders.PendingOrdersMinion.

This minion is scheduled to run every 5 minutes (default). The purpose of this minion is to process each order from the order list with name, “List-pendingorders-ByDate”. This list usually holds the orders that are in the status = “Pending”, which is the first status set once an order is placed.

This minion executes the IPendingOrdersMinionPipeline which executes the following blocks in order.

Sitecore.Commerce.Plugin.Orders
IPendingOrdersMinionPipeline (Sitecore.Commerce.Plugin.Orders.PendingOrdersMinionArgument => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.ValidatePendingOrderBlock (Sitecore.Commerce.Plugin.Orders.PendingOrdersMinionArgument => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.ValidateOrderAvailabilityBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.DelayedAvailability.ProcessMixedOrderBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.ReleaseOrderBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Payments.CreateOrderSalesActivitiesBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.GiftCards.ProcessGiftCardSettlementBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.ProcessProblemOrderBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.PersistOrderSalesActivitiesBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)
     ------------------------------------------------------------
     Plugin.Orders.PersistAndMoveOrderBlock (Sitecore.Commerce.Plugin.Orders.Order => Sitecore.Commerce.Plugin.Orders.Order)

Out of these, we will go through few of the blocks which are responsible for moving orders through different lists

  • ProcessMixedOrdersBlock: This block is responsible for checking the item availability for the cart product. If it is not available at the time of processing, it is set to Status = “WaitingForAvailability” and then moved to a new list, “List-WaitingForAvailabilityOrders-ByDate”.
  • ReleaseOrderBlock: Assuming the product is available, it will move onto the next block, ReleaseOrderBlock which sets the order status to “Released” and moves the order to a new list, “List-ReleasedOrders-ByDate”.
  • ProcessProblemOrderBlock: Each of these blocks have a validation based on Order status. If an order doesn’t satisfy these checks, order will be set to “Problem” status and moved “List-ProblemOrders-ByDate

Till now, you have noticed the order has been moved to multiple lists, but a copy of this order is still part of the PendingOrdersList. The last block of this pipeline, PersistAndMoveOrderBlock is responsible to remove the order from this list so that it is not picked up by the minion during its next run.

The different types of OrderLists are defined under Sitecore.Commerce.Plugin.Orders.KnownOrderListsPolicy and a couple under Sitecore.Commerce.Plugin.Orders.DelayedAvailability.KnownOrdersDelayedAvailabilityListsPolicy.

Steps involved in moving order to a new list:

  1. Get TransientListMembershipsComponent component from Order
  2. Check to make sure you are setting the correct status before moving an order to a new list, this step is optional and not needed for the move
  3. Set the membership to new list from KnownOrderListsPolicy

var transientListMembershipsComponent = order.GetComponent();
                if (transientListMembershipsComponent != null)
                {
                    order.Status = context.GetPolicy().Completed;
                    transientListMembershipsComponent.Memberships.Add(context.GetPolicy().CompletedOrders);

                    context.Logger.LogInformation($"{Block.Name}: order '{order.Id}' is now set to completed status.", Array.Empty());
                }

Steps involved in removing order from a list:

  1. Define a new ListEntitiesArgument with OrderId and ListName (You can find list names from KnownOrderListsPolicy)
  2. Run RemoveListEntitiesPipeline with the argument which will move the order from the list specified in step 1
var listEntitiesArgument = new ListEntitiesArgument((IEnumerable(string))new string[1]
                {
                   order.Id
                }, "PendingOrders");

                var removeListEntitiesArgument = await _removeListEntitiesPipeline.Run(listEntitiesArgument, context);

These OrderLists are very helpful in order to review orders based on status, fulfillment, cancellations. etc., If managed properly, it is very helpful for reporting and maintenance.

For more blogs about Sitecore Experience Commerce, please visit this link. For information on XCentium's Sitecore Commerce services, please click here

SEARCH ARTICLES