I've created an example that runs in a web console (hence it's modified a little to work in that context). It will work in yours too as the basics of the linq expression is the same.
the products i have in session.query<Product> should just be the list of products you want to order by.
Hope this helps.
Best regards
Morten
var sessionProvider = GetSessionProvider();
using (var session = sessionProvider.GetSession())
{
var orders = session.Query<OrderLine>();
var products = session.Query<Product>();
var ordersStatistics =
from orderLine in orders
join product in products
on new {orderLine.Sku, orderLine.VariantSku} equals new {product.Sku, product.VariantSku}
group orderLine by new {orderLine.Sku, orderLine.VariantSku}
into grouped
select new
{
Count = grouped.Count(),
Sku = grouped.Key.Sku,
VariantSku = grouped.Key.VariantSku,
};
var statistics = ordersStatistics.OrderByDescending(x => x.Count);
foreach (var ordersStatistic in ordersStatistics)
{
}
}
Sort products by most sold in the category
Hallo, I'm lookin for some hints on how to sort my products after most sold items in the category, my solution is based on the demo razor store.
Hello Kim,
I've created an example that runs in a web console (hence it's modified a little to work in that context). It will work in yours too as the basics of the linq expression is the same.
the products i have in session.query<Product> should just be the list of products you want to order by.
Hope this helps.
Best regards
Morten
Cool, thats what I need to get started.
is working on a reply...