Php Magento:从1.3升级到1.7后,Toolbar.phtml中的Mage\u目录\块\产品\列表\工具栏缺少集合
升级后,我遇到了以下错误:Php Magento:从1.3升级到1.7后,Toolbar.phtml中的Mage\u目录\块\产品\列表\工具栏缺少集合,php,magento,Php,Magento,升级后,我遇到了以下错误: Fatal error: Call to a member function getSize() on a non-object in ./app/design/frontend/base/default/template/catalog/product/list/toolbar.phtml on line 34 违规行: 经过快速调试后,我发现getCollection返回null。作为解决方法,我手动设置集合: $collection = Mage::getMo
Fatal error: Call to a member function getSize() on a non-object in ./app/design/frontend/base/default/template/catalog/product/list/toolbar.phtml on line 34
违规行:
经过快速调试后,我发现getCollection返回null。作为解决方法,我手动设置集合:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*');
$this->setCollection($collection);
我的问题是,为什么不设置集合?通常在哪里设置?通常在HTML之前的父
目录/产品列表
块的\u方法中设置
#File: app/code/core/Mage/Catalog/Block/Product/List.php
protected function _beforeToHtml()
{
$toolbar = $this->getToolbarBlock();
// called prepare sortable parameters
$collection = $this->_getProductCollection();
// use sortable parameters
if ($orders = $this->getAvailableOrders()) {
$toolbar->setAvailableOrders($orders);
}
if ($sort = $this->getSortBy()) {
$toolbar->setDefaultOrder($sort);
}
if ($dir = $this->getDefaultDirection()) {
$toolbar->setDefaultDirection($dir);
}
if ($modes = $this->getModes()) {
$toolbar->setModes($modes);
}
// set collection to toolbar and apply sort
$toolbar->setCollection($collection);
$this->setChild('toolbar', $toolbar);
Mage::dispatchEvent('catalog_block_product_list_collection', array(
'collection' => $this->_getProductCollection()
));
$this->_getProductCollection()->load();
return parent::_beforeToHtml();
}
特别是这一行
$toolbar->setCollection($collection);
我猜您的系统经过了大量修改,以至于工具栏块不再有目录/产品列表
作为父项。我自定义了一些核心文件,完全忘记了它,这就是其中之一,谢谢!