Search code examples
sitecoresitecore8microsoft-commerce-server

Sitecore Commerce Server - get full order list


I have a task: create a custom admin page in Sitecore to show FULL order history. I found a way to get order history per visitor, but couldn't find anything to get a full list of orders.

To get an order list per visitor we can use method

public virtual GetVisitorOrdersResult GetVisitorOrders(GetVisitorOrdersRequest request);

from class Sitecore.Commerce.Services.Orders.OrderServiceProvider and assembly: Sitecore.Commerce

I think we can get all users and after that get orders for each user. However, I don't think that it is a best way to solve the task. I will appreciate if you advice any other way to get all data.

Thank you in advance for the help.

P.S. I am using Sitecore 8.


Solution

  • I think I found the solution

    var contextManager = new CommerceServerContextManager();  //using Sitecore.Commerce.Connect.CommerceServer;
    OrderManagementContext orderManagementContext = contextManager.OrderManagementContext;
    var orderManager = orderManagementContext.PurchaseOrderManager;
    
    CultureInfo culture = new CultureInfo("en-US");
    DataSet searchableProperties = orderManager.GetSearchableProperties(culture.ToString());
    SearchClauseFactory searchClauseFactory = orderManager.GetSearchClauseFactory(searchableProperties, "PurchaseOrder"); //using CommerceServer.Core; Assembly CommerceServer.Core.CrossTier
    SearchClause searchClause = searchClauseFactory.CreateClause(ExplicitComparisonOperator.OnOrAfter, "Created", StartDate);
    
    SearchOptions options = new SearchOptions();
    options.SetPaging(10, 1);
    
    var result = orderManager.SearchPurchaseOrders(searchClause, options);
    

    Might be useful for somebody else.