【问题标题】:Add "Sort By" to custom product view将“排序依据”添加到自定义产品视图
【发布时间】:2012-09-21 10:07:03
【问题描述】:

我正在尝试将“排序依据”下拉菜单添加到我的自定义产品视图中。 它适用于寻呼机,但使用分拣机时我总是出错。

这是我尝试的:

protected function _prepareLayout()
{
    parent::_prepareLayout();


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

    $toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', 'custom.toolbar');
    $toolbar->setCollection($this->getCollection());
    $toolbar->setAvailableOrders($orders);

    $pager->setCollection($this->getCollection());
    //  $pager->setAvailableLimit(array(10=>10));

    //$pager->setLimit(2);
    $pager->setDefaultOrder(array('popularity_by_sells'=>'popularity_by_sells'));

    $pager->setCollection($this->getCollection());
    $pager->setShowPerPage(false);
    $pager->setShowAmounts(false);
    $pager->setDefaultOrder('popularity_by_sells');
    $this->setChild('pager', $pager);
    $this->getCollection()->load();
    return $this;
}


public function getPagerHtml()
{
    return $this->getChildHtml('pager');
}

public function getToolbarHtml(){
    return $this->getChildHtml('toolbar');
}

这里我得到了致命错误:

在第 738 行的 [...]\src\app\code\local\Mage\Catalog\Block\Product\List\Toolbar.php 中的非对象上调用成员函数 getId()

【问题讨论】:

    标签: php magento sorting toolbar


    【解决方案1】:

    我发现 getLimit() 函数是一个自定义函数,并简单地添加了 is_object() 在 if 子句中。

    public function getLimit(){
        $currentCategory = Mage::registry('current_category');
        if ($currentCategory !== false && is_object($currentCategory))
        {[...]}
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-05
      • 2016-06-18
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      相关资源
      最近更新 更多