I would like to sort each of my layered navigation filters by # of items in each filter.
Here's what shows now-
What I want to show-
I've been looking at catalog/layer/filter.phtml, but I can't figure out how to sort magento collections.
Ideally I want something like this:
$this->getItems()->order('Count Desc')
How can I accomplish this?
Found the way to do this-
Modified Mage/Catalog/Model/Layer/Filter/Abstract.php
to re-sort using count in the getItems
method.
public function getItems()
{
if (is_null($this->_items)) {
$this->_initItems();
}
//5-16-11 Custom sort
$items = $this->_items;
usort($items, array("Mage_Catalog_Model_Layer_Filter_Abstract", "sortByCount"));
return $items;
}
public static function sortByCount($a, $b)
{
if ($a->getCount() == $b->getCount()) {
return 0;
}
return ($a->getCount() > $b->getCount()) ? -1 : 1;
}
A good place to start is Mage/Catalog/Model/Layer/Filter/Attribute.php. The list is built there..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With