Developer forum

Forum » Dynamicweb 10 » Customer Order (My orders) need to add additional filters

Customer Order (My orders) need to add additional filters

Klumpford
Reply

Hi 

I’m using the Customer Experience Center (formerly Customer Center) in Dynamicweb 10 along with Swift to allow users to view and search their orders.

The default search includes things like order ID, status and date range.

I’d like to add an additional filter — for example, to allow users to filter orders by a custom field like "Item no", "address".

1. What’s the recommended way to extend or customize the order search in the Forum/Customer Experience Center?

2. Can this be done through configuration, or do I need to override a controller/viewmodel? 

Note: Filtertext which is available in DW9 allows to search the Order information not order item details.

Thanks.

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Klumpford

You can use these parameters when fitlering orders:

  • FilterOrderStateId (e.g. "State1" which is an ID of an orderstate)
  • FilterFromDate
  • FilterToDate
  • FilterOrderId
  • FilterText (This is the search

To control the list you have these parameters:

  • PageSize (E.g. 12)
  • SortOrder (ASC or DESC)
  • SortBy (E.g. 'OrderDate' - here you can use any field on the EcomOrders table, e.g. "OrderCustomerAddress", "OrderDeliveryAddress" or "OrderCustomerAddressId" etc. If you have created custom fields you can also use those)
  • PageNum (e.g. 2)

If you have custom fields on the order, you can order by those. You cannot order by custom fields on orderlines as that does not make sense when sorting orders.

This is not extendable.

I can see that the CustomerExperienceCenter does not search orderlines when using FilterText paramter in the same way as the old customer center module did. I have just changed that and will release that in 10.15. Devops#23853

 
Dynamicweb Employee
Carsten Boll
Reply

I added the missing parameters to the CEC implementer documentation :)

 
Klumpford
Reply

Nicolai Pedersen, Thank you for sharing the detail response.

I have implemented the changes, which is available in the documentation, as you said. But we need an option to search by Item number which is easy to search for different orders based on the item. 

Kindly share how to override this either by creating the custom MVC controller class or Api controller to add additional filters. I can see examples of creating API controller, but this Page is the GET request so I cannot use it to ovverride.

Also if possible can you share an example on use the controller class,

Thanks.

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi

The changes coming with Devops#23853 will give you search in item numbers (orderlines 

The custom way of doing this is using the search filter for orders directly in your template or in custom module:

 

You can create a search filter for orders like this:

private OrderSearchFilter CreateSearchFilter(CustomerExperienceCenterSettings settings)
{
    var filter = new OrderSearchFilter() { DoSearch = true };
    var pageview = PageView.Current();
    if (pageview is object && pageview.Area is object)
    {
        filter.SelectedShopId = pageview.Area.EcomShopId;
    }

    filter.Completed = OrderSearchFilter.CompletedStates.Both;
    switch (settings.OrderTypeToShow)
    {
        case OrderType.Order:
            {
                filter.Completed = OrderSearchFilter.CompletedStates.Completed;
                break;
            }

        case OrderType.Cart:
            {
                filter.IsCart = true;
                filter.Completed = OrderSearchFilter.CompletedStates.NotCompleted;
                break;
            }

        case OrderType.LedgerEntry:
            {
                filter.IsLedgerEntries = true;
                break;
            }

        case OrderType.Quote:
            {
                filter.IsQuotes = true;
                filter.Completed = OrderSearchFilter.CompletedStates.NotCompleted;
                filter.IsCart = false;
                break;
            }

        case OrderType.Recurringorder:
            {
                filter.IsRecurringOrder = true;
                break;
            }
    }

    filter.OrderStateId = RequestContext("FilterOrderStateId");
    filter.FromDate = Converter.ToDateTime(RequestContext("FilterFromDate"), DateTime.MinValue).Date;
    filter.ToDate = Converter.ToDateTime(RequestContext("FilterToDate"), DateTime.MaxValue).Date;
    filter.SearchOrderId = RequestContext("FilterOrderId");
    filter.TextSearch = RequestContext("FilterText");

    if (!string.IsNullOrEmpty(filter.TextSearch))
    {
        filter.DoSearch = true;
        filter.DoTextSearchInProducts = true;
        filter.SearchInCustomOrderFields = true;
    }

    string orderBy = string.Empty;
    if (!string.IsNullOrEmpty(settings.SortByField))
    {
        CustomerExperienceCenterSettings.FieldsForSorting.TryGetValue(settings.SortByField, out orderBy);
    }

    if (string.IsNullOrEmpty(orderBy))
    {
        orderBy = "OrderDate";
    }

    filter.OrderBy = $"{orderBy} {settings.SortOrder}";
    int pageNumber = Converter.ToInt32(RequestContext("PageNum"));
    if (pageNumber <= 0)
    {
        pageNumber = 1;
    }

    filter.PageNumber = pageNumber;
    filter.PageSize = settings.PageSize;
    filter.CustomerId = CustomerId;
    if (settings.UseCustomerNumber)
    {
        filter.CustomerNumber = Services.Orders.GetCustomerNumber(filter.CustomerId);
    }

    filter.IncludeImpersonation = settings.UseImpersonationIds;
    filter.IncludeUserAndSecondaryUserIds = settings.UseUserAndSecondaryUserIds;
    return filter;
}

And use the filter as a parameter on the orderservice:

 var searchResult = Services.Orders.GetOrdersBySearch(searchFilter);
 int totalOrdersCount = searchResult.TotalCount;
 int pageCount = 0;
 var orderRange = searchResult.GetResultOrders();

And then you have a list of orders you can iterate instead of using the order viewmodels:

foreach(var order in orderRange)
{
    var orderId = order.Id;
}
Votes for this answer: 1
 
Klumpford
Reply

Nicolai Pedersen, Thank you for sharing the response with source code.

Based on the suggestion added the logics to implement the custom filter. But since the page is using "GET" request which loads the data directly its causing twice the filtering of the data.

How to ovveride the GET request to call the custom logics which i have implemented and return view with "OrderlistviewModel" data.

Thanks,

 

You must be logged in to post in the forum