Magento: Get all the products from the product collection, ignoring the established limits?

I want to iterate over all the products in the product collection specified in the Mage_Catalog_Block_Product_List_Toolbar block, ignoring the restrictions set earlier by "setPageSize ()" and "setCurPage ()". My approach is as follows:

/** @var Mage_Catalog_Block_Product_List_Toolbar $this */ //... $collection = $this->getCollection(); // Remove the LIMIT and OFFSET parts from the generated SQL query: $collection->getSelect()->reset(Zend_Db_Select::LIMIT_COUNT); $collection->getSelect()->reset(Zend_Db_Select::LIMIT_OFFSET); // Reload the collection using the new SQL query: $collection->load(); foreach($collection as $product) { // ... } // ... 

The problem is that the collection does not seem to reload, so the restrictions that were set earlier still exist. What am I missing here? Is the collection blocked or something that I cannot change?

+7
source share
1 answer

The collection that you use in the toolbar block of the product list is usually already loaded and installed into the toolbar instance using Mage_Catalog_Block_Product_List::_beforeHtml() .

Just resetting the score and offset for the operator is not enough.

You also need to reset the properties

 Varien_Data_Collection::_isCollectionLoaded Varien_Data_Collection::_pageSize 

This can be done using

 $collection->clear(); $collection->setPageSize(false); 

Insert these instructions between your reset and load , and everything will be fine.

+12
source

All Articles