find this :
$products = $category->getProducts((int)($params[‘cookie’]->id_lang), 1, ($nb ? $nb : 10));
directly after that code, add this :
if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); }
If you change it to
$nb1 = 20;
$products = $category->getProducts((int)($params[‘cookie’]->id_lang), 1, ($nb1 ? $nb1 : 10));
if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : 10)); }
it will select random from the first 20 products.. And show whatever $nb is set to in configuration
thank you very much. i was looking how to achieve random functionality in the categoryproducts module on product page.. fits great. thanx
thanks
Hello,
In my store this file like this:
function hookHome($params)
{
global $smarty;
$category = new Category(1, (int)Configuration::get(‘PS_LANG_DEFAULT’));
$nb = (int)Configuration::get(‘HOME_FEATURED_NBR’);
$smarty->assign(array(
‘products’ => $category->getProducts((int)$params[‘cookie’]->id_lang, 1, ($nb ? $nb : 10)),
‘add_prod_display’ => Configuration::get(‘PS_ATTRIBUTE_CATEGORY_DISPLAY’),
‘homeSize’ => Image::getSize(‘home’)));
return $this->display(__FILE__, ‘homefeatured.tpl’);
}
}
How do I change it?
what if you you would like it to select random products from you entire product list not just first 20?
Hi mike ,
U can use like this for $nb1
$nb1 = {$products|@count};
Helo, new code:
function hookHome($params)
{
global $smarty;
$category = new Category(1, (int)Configuration::get(‘PS_LANG_DEFAULT’));
$nb = (int)Configuration::get(‘HOME_FEATURED_NBR’);
$products = $category->getProducts((int)($params[‘cookie’]->id_lang), 1, ($nb ? $nb : (int)$this->defaultNumberProducts));
if ($products) { shuffle($products); array_splice($products, ($nb ? $nb : (int)$this->defaultNumberProducts)); }
$smarty->assign(array(
‘products’ => $products,
‘add_prod_display’ => Configuration::get(‘PS_ATTRIBUTE_CATEGORY_DISPLAY’),
‘homeSize’ => Image::getSize(‘home’)));
return $this->display(__FILE__, ‘homefeatured.tpl’);
}
I have PS 1.6.0.9 and would like to have random products on my front page (home page) using all of my products. Is it possible?
Yes its possible.
I’ve tried several modules and guidelines without any luck. Can I use the description above in my version?
Found it