5

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

这是现在显示的 -

  • 书籍 - 1
  • CD - 2
  • DVD - 20

我想展示的——

  • DVD - 20
  • CD - 2
  • 书籍 - 1

我一直在查看目录/层/filter.phtml,但我不知道如何对 magento 集合进行排序。

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

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

我怎样才能做到这一点?

4

2 回答 2

5

找到了这样做的方法-

修改为在方法Mage/Catalog/Model/Layer/Filter/Abstract.php中使用 count 重新排序。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;
}
于 2011-05-16T16:41:33.103 回答
3

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

于 2011-05-15T23:36:08.830 回答