Netismine

Work

Customers who bought this

“Customers who bought this also bought” is a rather common requirement for store owners. And while there are many modules out there doing this, it’s surprising to know that this is, in essence, actually a very simple SQL query. Most of the work is just displaying the list on frontend and creating correct structure. First you need to fetch all order ids that have a specific product id in them, then select all product ids from that subset, exclude the product id of current product and sort it by number of times product id appeared in the sales table – and it all fits into a single query. So if someone is trying to sell you a story that this is a huge feature, know that it’s actually only 3-5 hours of work.

1 comment

One Response to Customers who bought this

  1. Robert Went says:

    Do you have some example code? :)

    Also, if you are making queries for each product viewed, would this slow the site down or is there some way to cache the results?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">