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.
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
}
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
I haven't tested this, but maybe this could help you get started:
is working on a reply...
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.