开发者

Magento Layered Navigation - Sort By Count

开发者 https://www.devze.com 2023-03-05 20:19 出处:网络
I would like to sort each of my layered navigation filters by # of item开发者_JS百科s in each filter.

I would like to sort each of my layered navigation filters by # of item开发者_JS百科s in each filter.

Here's what shows now-

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

What I want to show-

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

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..

0

精彩评论

暂无评论...
验证码 换一张
取 消