Question

On the catalog product list view I can use shuffle() on the product collection however it only shuffles a small proportion (e.g. 10) of the full collection (hundreds). There is also infinite ajax scroll on this page. The shuffled products are those on the first 'page' before the scroll loads more.

$_productCollection=$this->getLoadedProductCollection();
....
$items = $_productCollection->getItems();
shuffle($items);
foreach ($items as $_product):
....

Is there any way I can keep the scrolling feature but shuffle the full collection?

One way to shuffle all products is the following, but this takes an age to load and has no scrolling.

$_productCollection = $this->getLoadedProductCollection();
$_productCollection->clear();
$_productCollection->setPage(1,99999);
Was it helpful?

Solution

I think you can better add a line like this:

$_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));

This randomises the collection. but not does it external like shuffle does (just shuffling the array)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top