0

我在主页上显示带有滑块的图像的所有制造商作为块。在那里我放了查看全部链接,单击该链接时,它会将新 pahe 中的所有制造商显示为类别页面。我创建了manufacturer.php如下

<?php
class Bc_Manufacturer_Block_Manufacturerpage extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
    return parent::_prepareLayout();
}

public function getManufacturer()     
{ 
    if (!$this->hasData('manufacturer')) {
        $this->setData('manufacturer', Mage::registry('manufacturer'));
    }
    return $this->getData('manufacturer');

   }
public function getToolbarHtml() {

    $this->setToolbar($this->getLayout()->createBlock('catalog/product_list_toolbar', 'Toolbar'));

    $toolbar = $this->getToolbar();

    $toolbar->enableExpanded();

    $toolbar->setAvailableOrders(array(

            'ordered_qty' => $this->__('Position'),

            'name' => $this->__('Name'),

            'price' => $this->__('Price')

        ))

        ->setDefaultDirection('desc')

        ->setCollection($this->_productCollection);


    $pager = $this->getLayout()->createBlock('page/html_pager', 'Pager');

    $pager->setCollection($this->_productCollection);

    $toolbar->setChild('product_list_toolbar_pager', $pager);

    return $toolbar->_toHtml();

}

}

还调用 manufacurerpage.phtml 文件中的 getToolbarHtml() 函数,如 getToolbarHtml() 下所示?>

    <div class="grid-type-full">
        <?php foreach($maufacturers as $manufacturer): ?>
            <?php if(Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName())): ?>

                <?php if ($i++%$_columnCount==0): ?>
                    <ul class="products-grid">
                <?php endif ?>
                        <li style="position: relative; float: left; display: inline-block; " class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                            <a href="<?php echo $this->getBaseUrl()."catalogsearch/advanced/result/?manufacturer[]=".$manufacturer->getMenufecturerName() ?>">
                                <?php echo $this->getLayout()->createBlock('core/template')->setmanufacturerimage($manufacturer->getFilename())->setlegend($manufacturer->getLegend())->setListPageFlag(1)->setTemplate('manufacturer/manufacturer_resize.phtml')->toHtml(); ?>
                                <div class="manufacturer-name">
                                    <?php echo Mage::getModel('eav/entity_attribute_source_table')->setAttribute(Mage::getModel('eav/entity_attribute')->load(Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product',"manufacturer")))->getOptionText($manufacturer->getMenufecturerName()) ?>
                                </div>
                            </a>
                        </li>
                 <?php if ($i%$_columnCount==0 && $i!=count($maufacturers)): ?>
                    </ul>
                <?php endif ?>
            <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    </div>

<div class="toolbar-bottom">
    <?php echo $this->getToolbarHtml() ?>
</div>

运行后我得到了如下错误

致命错误:在 C:\wamp\www\magento\jumbostore\app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php 中的非对象上调用成员函数 setCurPage() 第 225 行

任何人都有解决方案请帮助我...

谢谢你..

4

1 回答 1

0

虽然这是一个很晚的回应,但我遇到了类似的问题,发现setCollection() 没有得到产品集合。

app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php您可以在第 221 行附近的 Your path 找到代码。

 <?php   
public function setCollection($collection)
{
    $this->_collection = $collection;

    $this->_collection->setCurPage($this->getCurrentPage()); //*****HERE

    // we need to set pagination only if passed value integer and more that 0
    $limit = (int)$this->getLimit();
    if ($limit) {
        $this->_collection->setPageSize($limit);
    }
    if ($this->getCurrentOrder()) {
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }
    return $this;
}
?>

请尝试检查您的函数是否正在获取集合。希望这是一些帮助!

于 2013-10-03T06:30:39.417 回答