Jump to content

Randomize products in homepage


Recommended Posts

If I have 12 products shown in homepage but I have, tipically, 50 products suitable to be shown, how can I do this?

My wish is to have 50 or more products in HOME category and 12 of this, random select, shown in homepage each load of the page.

 

It is possible?

 

Prestashop 1.4.8.2 with Prestahop-Alt theme

Edited by gtonti (see edit history)
Link to comment
Share on other sites

Hello gtonti,

 

Yes thats possible, great thanks goes to IWAN1979 for this great fix and his code found here http://iwanmadan.com/prestashop-random-product-listing/.

 

Replace the following code below found in /modules/homefeatured/homefeatured.php

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));

with:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);
if ($products) {
shuffle($products);
array_splice($products, ($nb ? $nb : 10));
}

 

This works perfect on PS 1.4.8.2. as i m also use this on this PS version with succes;)

 

Best regards,

 

ysco..

Edited by ysco (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 7 months later...
  • 1 month later...

Hello gtonti,

 

Yes thats possible, great thanks goes to IWAN1979 for this great fix and his code found here http://iwanmadan.com...oduct-listing/.

 

Replace the following code below found in /modules/homefeatured/homefeatured.php

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10));

with:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);
if ($products) {
shuffle($products);
array_splice($products, ($nb ? $nb : 10));
}

 

This works perfect on PS 1.4.8.2. as i m also use this on this PS version with succes;)

 

Best regards,

 

ysco..

 

This work perfectly in PS 1.5.3.

 

Thanks ysco

Link to comment
Share on other sites

  • 3 weeks later...
×
×
  • Create New...