Jump to content

How to display products randomly homepage featured


Recommended Posts

I am using version 1.5.2. I have set my featured to 8, and these do list proudly on my homepage. I am wondering if there is a way to change at random the images which get listed. Example, if I open my site in firefox and my site in IE, I will not show the exact same images, image position etc.

 

I would like these 8 to say be pulled (used) from all the new images/products. Example if at one time I have added 20 products, it will choose 8 from them, then say tomorrow, I add another 50, for a total of 70. How may I get it to random featured products from the total 70 and not just the first 20 I added?

 

I did follow the steps from here...http://mypresta.eu/en/art/tips-and-tricks/how-to-display-products-randomly-in-prestashop-home-featured-module.html

 

and this only randomizes the order of the 8 which are already there.

 

Thankx for the help in advance...

Link to comment
Share on other sites

Try this. Instead code

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

shuffle($products);

 

use

 

 

$products = $category->getProducts((int)Context::getContext()->language->id, 1, 100);
if ($products) { 
shuffle($products); 
array_splice($products, ($nb ? $nb : 10)); 
}

 

This part of code first gets 100 products, randomize it's order and then takes defined set

of products. Note that if you have noticeable performance issues decrease number of

products (here is 100 just for example).

  • Like 4
Link to comment
Share on other sites

  • 5 months later...
  • 1 year later...
  • 2 years later...
×
×
  • Create New...