Magento Layered Navigation - Sort by Number

I would like to sort each of my layered navigation filters by # elements in each filter.

Here's what it shows now -

  • Books - 1
  • CD - 2
  • DVD - 20

What I want to show -

  • DVD - 20
  • CD - 2
  • Books - 1

I looked at the /layer/filter.phtml directory, 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 do this?

+5
source share
2 answers

Found a way to do this -

Changed Mage/Catalog/Model/Layer/Filter/Abstract.phpto re-sort using count in a method getItems.

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;
}
+5
source

Mage/Catalog/Model/Layer/Filter/Attribute.php. ..

+3

All Articles