Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Kim Søjborg Pedersen 71 posts 275 karma points
    Jan 16, 2014 @ 14:07
    Kim Søjborg Pedersen
    0

    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.

  • Morten Skjoldager 440 posts 1499 karma points
    Jan 17, 2014 @ 13:12
    Morten Skjoldager
    100

    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

               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)
                    {
    
                    }
                }
  • Kim Søjborg Pedersen 71 posts 275 karma points
    Jan 17, 2014 @ 13:17
    Kim Søjborg Pedersen
    0

    Cool, thats what I need to get started.

Please Sign in or register to post replies

Write your reply to:

Draft