D
D
Dmitry Yakovlev2014-10-12 19:05:22
PHP
Dmitry Yakovlev, 2014-10-12 19:05:22

How to display the last viewed products in the online store?

Tell me the algorithm or describe the procedure for displaying the last viewed products.
I implemented it in the following way:
1) when the user gets to the product-view page (product description page). I write to the product id array and save it in a cookie . Then I check if the number of array elements does not exceed a given number (for example: show only the last 20 products), if more, I delete the last element.
2) I form a string for the SQL query where product.id in (id1, id2...) from the id array , which is stored in the cookie . And the last step is displaying the last item.
In my implementation, the order in which the product is viewed is not preserved. That is, where id (3, 2, 5) will return 2, 3, 5 at the beginning

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Taratin, 2014-10-12
@Taraflex

when the user lands on the product-view page (product description page). I write to the product id array and save it in a cookie.

Use localStorage and then not only the product id will fit there, but also all the necessary information. Then you will not need to make additional requests later.

P
Pavel Gogolinsky, 2014-10-12
@gogolinsky

The move is correct.
Save the viewing date as well. Date('H:i:s'). And then sort by it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question