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.

  • Matt Brailsford 2958 posts 15629 karma points MVP 7x c-trib
    Jan 14, 2013 @ 14:47
    Matt Brailsford
    0

    Best sellers

    What's is a best way to get a list of X best sellers from a catalog using the API?

    Many thanks

    Matt

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Jan 14, 2013 @ 18:25
    Nickolaj Lundgreen
    0

    uCommerce uses a SP called uCommerce_GetProductTop10 to generate the Top 10 product overview found in the backend.

    If you are looking for a more flexible solution i think you maybe could get some inspiration from a method i once wrote, to rank products:

     

     public static IOrderedEnumerable<Ranking> RankPassedProducts(List<string> skus)
            { 
                var validOrders = PurchaseOrder.All().Where(x => x.CompletedDate != null).ToList();
                var validOrderLines = validOrders.SelectMany(y => y.OrderLines);
    
    
                var rankingList = new List<Ranking>();
                foreach (var sku in skus)
                {
                    var buys = validOrderLines.Where(x => x.Sku == sku).ToList().Sum(y => y.Quantity);
                    var newRanking = new Ranking() { Buys = buys, Sku = sku };
                    rankingList.Add(newRanking);
    
                }
                var outputList = rankingList.OrderByDescending(y => y.Buys);
                return outputList;
    
            }

    It takes some time, so i made a caching layer to speed things up.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies