I want to iterate over all products in the product collection given in the block Mage_Catalog_Block_Product_List_Toolbar, ignoring the limits that were set before by "setPageSize()" and "setCurPage()". My approach looks like the following:
/** @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 seems not to be reloaded, so the limits that were set before are still there. What am I missing here? Is the collection locked or something so that I can't change it?
The collection you use in the product list toolbar block, usually is already loaded before and set to the toolbar instance by Mage_Catalog_Block_Product_List::_beforeHtml()
.
Just resetting count and offset for the statement is not enough.
You additionally need to reset the properties
Varien_Data_Collection::_isCollectionLoaded
Varien_Data_Collection::_pageSize
This can be done by
$collection->clear();
$collection->setPageSize(false);
Insert these instructions between your reset
's and the load
and you should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With