Magento:从产品系列中获取所有产品,忽略设定的限制?

Sub*_*urf 8 collections magento

我想迭代块Mage_Catalog_Block_Product_List_Toolbar中给出的产品集合中的所有产品,忽略"setPageSize()"和"setCurPage()"之前设置的限制.我的方法如下所示:

/** @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)
{
    // ...
}
// ...
Run Code Online (Sandbox Code Playgroud)

问题是,集合似乎没有重新加载,因此之前设置的限制仍然存在.我在这里错过了什么?集合是锁定还是某种东西让我无法改变它?

Jür*_*len 13

您在产品列表工具栏块中使用的集合通常已在之前加载并设置为工具栏实例Mage_Catalog_Block_Product_List::_beforeHtml().

只重置语句的计数和偏移量是不够的.

您还需要重置属性

Varien_Data_Collection::_isCollectionLoaded
Varien_Data_Collection::_pageSize
Run Code Online (Sandbox Code Playgroud)

这可以通过

$collection->clear();
$collection->setPageSize(false);
Run Code Online (Sandbox Code Playgroud)

插入您之间的这些指令reset的和load你应该罚款.