Figure 15-1. Product recommendations in the product details page
The shopping cart page gets a similar addition, as shown in Figure 15-2.
CHAPTER 15 ?– PRODUCT RECOMMENDATIONS 462
Figure 15-2. Product recommendations in the shopping cart page
Selecting Recommendations from the Database
The technical challenge for implementing the new feature lies in writing the database queries
that return the product recommendations. Writing a SELECT query that finds the products that
were ordered together with another product (to generate product recommendations), or with
another set of products (to generate shopping cart recommendations), is not overly complex
but not trivial either.
Let??™s start with the product recommendations. You need to find out what other products
were bought by customers who bought the product for which you??™re calculating the recommendations
(in other words, determine the ???customer who bought this product also bought . . .???
information).
Our order_detail table contains the data for each of our orders. To determine what other
products were ordered together with a specific product, we would join two instances of the
order_detail table on their order_id fields. Joining multiple instances of a single table is just
like joining independent data tables that contain the same data (feel free to review the ???Joining
Data Tables??? section in Chapter 5 for a quick refresher about table joins).
Pages:
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582