I m trying get Best Seller option in select box at Category product listing.
I have already extended
class Mymodule_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{
protected function _construct()
{
parent::_construct();
}
public function getAvailableOrders()
{
$this->_availableOrder['bestseller'] = $this->__('Best Seller');
return $this->_availableOrder;
}
}
After that , I got Best Seller option in select box.
But, I don't known how to get it work.
Any help would be appreciated.
You need extend setCollection() too:
public function getAvailableOrders()
{
$this->_availableOrder['bestseller'] = $this->__('Best Seller');
return $this->_availableOrder;
}
public function setCollection($collection)
{
// ...
if ($this->getCurrentOrder()) {
if ($this->getCurrentOrder() == 'bestseller') {
// add needed joins to collection here to get 'bestseller' column in collection
}
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
return $this;
}
Btw, do you know that $this->__('Best Seller');
is bad style? As you know, $this->__()
is shortcut for current module data helper __() method. But if someone will extended your block in another module - that module data helper will be used to translate 'Best Seller' string to other languages. It is evident that in his module he may not have translation for 'Best Seller' string. That's why you must always use Mage::helper('your_module/data')->__()
for translation.