After the upgrade I was getting the error:
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
Offending line: <?php if($this->getCollection()->getSize()): ?>
After some quick debugging I found getCollection was returning null. As a workaround I manually set the collection:
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*');
$this->setCollection($collection);
My question, why isn't the collection being set? Where would it normally be set?
The is normally set in the parent catalog/product_list
block's _beforeToHtml
method.
#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();
}
Specifically this line.
$toolbar->setCollection($collection);
My guess would be your system was heavily modified such that the toolbar block no longer had catalog/product_list
as a parent.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.