Magento分层导航 - 按计数排序

Bri*_*ian 5 navigation magento layered

我想按每个过滤器中的#项对每个分层导航过滤器进行排序.

以下是现在显示的内容 -

  • 书籍 - 1
  • CD的 - 2
  • DVD's - 20

我要展示的内容 -

  • DVD's - 20
  • CD的 - 2
  • 书籍 - 1

我一直在看目录/ layer/filter.phtml,但我无法弄清楚如何对magento集合进行排序.

理想情况下我想要这样的东西:

$ this-> getItems() - > order('Count Desc')

我怎么能做到这一点?

Bri*_*ian 5

找到了做到这一点的方法 -

修改Mage/Catalog/Model/Layer/Filter/Abstract.php为使用getItems方法中的count重新排序.

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;
}
Run Code Online (Sandbox Code Playgroud)


jos*_*va1 3

一个好的起点是 Mage/Catalog/Model/Layer/Filter/Attribute.php。该列表是在那里建立的..