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:39
    Matt Brailsford
    0

    Customers also bought

    Hi, 

    As anyone got an example of doing a list of products based upon what other people bought alongside the current product in the past, ie "Customers who bought this, also bought...".

    I'm doing this in Razor, so if there is an example using the API, that would be great.

    Cheers

    Matt

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

    I haven't tested this, but maybe this could help you get started:

    public static List<Product> AlsoBought(Product product)
            {
                //completed orders
                var allCompletedOrders = PurchaseOrder.All().Where(x => x.CompletedDate != null);
                //OrderLines with that product (or variant there of)
                var orderLinesWithProduct = allCompletedOrders.Where(y => y.OrderLines.Any(x => x.Sku == product.Sku));
                //List of order IDs where the product was bought
                var validOrderIds = orderLinesWithProduct.Select(x => x.OrderId).Distinct();
                //List of Orders
                var validOrders = validOrderIds.Select(x => PurchaseOrder.Get(x));
    
                return  //Now you can do a ranking of the OrderLines in validOrders to select the correct list of products
    
    
            }
  • 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