Jump to content

[SOLVED] how to display random products display in category

Recommended Posts



Im sorry if i didnt post in correct category

Im looking for a module that will do this


Example: we have 14 products in Babys->New Born->Diapers . All 14 products are displayed also in Babys , New Born and Diappers


In Diapers will be dispalyed in the mode i chose ( i can do that in category )

but in New Born and Babys i want to be displayed random ( shuffled )


Thank you and Best Regards

Share this post

Link to post
Share on other sites
  • 1 month later...

you can achieve it only with modification of controller.



add there condition like:

	if ($id_category==5){

where id_category==5 is a id of category where you want to shuffle results.



add this code in assignProductList() function, before smarty array definitions.

Share this post

Link to post
Share on other sites

i marked this topic as solved, if you will need any additional assistance related to this topic - feel free to continue discussion below

with regards,


Share this post

Link to post
Share on other sites
  • 9 months later...
public function initContent()
		if (!$this->customer_access)
		if (isset($this->context->cookie->id_compare))
			$this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare));	
		$this->productSort(); // Product sort must be called before assignProductList()
		if (!in_array($this->category->id, array(Configuration::get('PS_HOME_CATEGORY'), Configuration::get('PS_ROOT_CATEGORY'))))
			if ($id_category==6){shuffle($this->cat_products);}
			'category' => $this->category,
			'description_short' => Tools::truncateString($this->category->description),
			'products' => (isset($this->cat_products) && $this->cat_products) ? $this->cat_products : null,
			'id_category' => (int)$this->category->id,
			'id_category_parent' => (int)$this->category->id_parent,
			'return_category_name' => Tools::safeOutput($this->category->name),
			'path' => Tools::getPath($this->category->id),
			'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
			'categorySize' => Image::getSize(ImageType::getFormatedName('category')),
			'mediumSize' => Image::getSize(ImageType::getFormatedName('medium')),
			'thumbSceneSize' => Image::getSize(ImageType::getFormatedName('m_scene')),
			'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
			'allow_oosp' => (int)Configuration::get('PS_ORDER_OUT_OF_STOCK'),
			'comparator_max_item' => (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'),
			'suppliers' => Supplier::getSuppliers()

In front oficce shows error

Notice: Undefined variable: id_category in /.../controllers/front/CategoryController.php on line 111


what I did wrong??

thx in advance for help...

  • Like 1

Share this post

Link to post
Share on other sites
This topic is now closed to further replies.
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More