Jump to content

[Contribution] Randomize home page products with database


Recommended Posts

Since the php shuffle takes up much resource (in my case it was 1.2 seconds extra load time), here is a method of doing it in database.

 

SQL query:

 

SET @a:=0;
UPDATE ps_category_product SET position=@a:=@a+1 WHERE `id_category` = 2 ORDER BY RAND()

 

You can put it in the cron job at certain time interval or bookmark it and run it manually. If you don't have default sorting by position, you need to change the homefeatured/homefeatured.php in line 107, change

 

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

 

into

 

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), 'position', 'DESC');

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...