I’m trying to add the “Sort by” dropdown to my custom product view.
It worked with pager, but with sorter i get errors all the time.
This is what i try:
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');
}
Here i get the fatal error:
Call to a member function getId() on a non-object in […]\src\app\code\local\Mage\Catalog\Block\Product\List\Toolbar.php on line 738
I figured out that the getLimit() function was a custom function, and simply added is_object()
in the if-clause.