将“排序依据”添加到自定义产品视图

时间:2012-09-21 10:07:04

标签: php magento sorting toolbar

我正在尝试将“排序方式”下拉列表添加到我的自定义产品视图中。 它适用于寻呼机,但是随着分拣机,我总是会出错。

这是我尝试的:

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()

1 个答案:

答案 0 :(得分:0)

我发现getLimit()函数是一个自定义函数,只需添加is_object() 在if子句中。

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