• open /modules/homefeatured/homefeatured.php file
    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

    By admin

    10 thoughts on “Prestashop | Show Random Products In Home Featured”
    1. thank you very much. i was looking how to achieve random functionality in the categoryproducts module on product page.. fits great. thanx

    2. 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?

    3. 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’);
      }

        1. I’ve tried several modules and guidelines without any luck. Can I use the description above in my version?

    Leave a Reply

    Your email address will not be published. Required fields are marked *