2012-11-09 56 views
0

我得到的错误升级后:Magento的:缺少集合Mage_Catalog_Block_Product_List_Toolbar从1.3升级后toolbar.phtml 1.7

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 

出错行:<?php if($this->getCollection()->getSize()): ?>

一些快速的调试,我发现getCollection后返回null。作为解决方案,我手动设置集合:

$collection = Mage::getModel('catalog/product')->getCollection() 
      ->addAttributeToSelect('*'); 
$this->setCollection($collection); 

我的问题,为什么不是集合被设置?它通常会在哪里设置?

回答

1

通常在父项catalog/product_list块的_beforeToHtml方法中设置。

#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); 

我的猜测是你的系统被严重修改,使得工具栏块不再有catalog/product_list作为父母。

+1

我已经定制了一些核心文件,并完全忘记它,这是其中之一,谢谢! – PieSub