Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design
Showing posts with label random product listing. Show all posts
Showing posts with label random product listing. Show all posts

How to Display Random Product list on category/Product listing page in Magento

If you want to display or want to change your default product listing with random listing, just change following simple code.

The product listing page has already category filter applied, check the code at app/code/core/Mage/Catalog/Block/Product/List.php, you simply need to add the random filter there.

It is best practice to override your core file in your local directory instead of changing in core file. So copy file
from app/code/core/Mage/Catalog/Block/Product/List.php to app/code/local/Mage/Catalog/Block/Product/List.php

Now open this file Search _getProductCollection() function. In this function find out
$this->_productCollection = $layer->getProductCollection(); and comment this line and add following code just after this line...

$collection = $layer->getProductCollection();
$collection->getSelect()->order('rand()');
$this->_productCollection = $collection;

Now clear your cache and you are done.

 

Copyright @ 2017 HKBlog.