Change the dashboard orders chart

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
My client wants the chart to show the number of products sold and I changed this line in the LoadOrderStatistics method

_orderService
.SearchOrders(createdFromUtc: _dateTimeHelper.ConvertToUtcTime(searchMonthDateUser, timeZone), createdToUtc: _dateTimeHelper.ConvertToUtcTime(searchMonthDateUser.AddDays(1), timeZone), pageIndex: 0, pageSize: 1).TotalCount.ToString()


to this line:

.SearchOrders(createdFromUtc: _dateTimeHelper.ConvertToUtcTime(searchMonthDateUser, timeZone),
createdToUtc: _dateTimeHelper.ConvertToUtcTime(searchMonthDateUser.AddDays(1), timeZone), pageIndex: 0, pageSize: 1).Sum(x=>x.OrderItems.Sum(y=>y.Quantity)).ToString()


And of course that didn't work :) Any ideas on how to make this work?
6 years ago
(Not tested, but try...)

.SelectMany(o => o.OrderItems).Sum(oi => oi.Quantity)
6 years ago
SearchOrders returns PagedList<Order> and LINQ doesn't work the regular way, hence the problem I'm having, and your solutions gives the same result (That was the first version that a tried).

I do get results, but they're not correct. In my test DB, I have 3 orders from today, 2 are cancelled (I also have a question of why they show up in the stats) and one that is processing. I get 0 with both my and your version of the code...

The cancelled orders don't have any OrderItems in them because that was messing up my bestsellers stats (again why are the numbers from the cancelled orders taken into account?) and I modified the code to delete the OrderItems on cancellation. I should get a result of 2, but I get 0 for some reason, and for yesterday I get 1 for some reason, but there are 5 orders with a total of 11 products sold.
6 years ago
PagedList<Order> and LINQ work ok.  The problem is the 'pageSize: 1'.  The 'TotalCount' always returns the total # of orders; they didn't need the list of orders.

Remove the pageIndex & pageSize params. This works OK:

    value = _orderService.SearchOrders(
        createdFromUtc: _dateTimeHelper.ConvertToUtcTime(searchYearDateUser, timeZone),
        createdToUtc: _dateTimeHelper.ConvertToUtcTime(searchYearDateUser.AddMonths(1), timeZone) )
        .SelectMany(o => o.OrderItems)
        .Sum(oi => oi.Quantity)
        .ToString()


If you want to only include certain order or payment statuses, use the other prams:
...
        /// <param name="osIds">Order status identifiers; null to load all orders</param>
        /// <param name="psIds">Payment status identifiers; null to load all orders</param>
        /// <param name="ssIds">Shipping status identifiers; null to load all orders</param>
...
        IPagedList<Order> SearchOrders(int storeId = 0,
...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.