【问题标题】:Magento Layered Navigation - Sort By CountMagento 分层导航 - 按计数排序
【发布时间】:2011-08-25 22:15:53
【问题描述】:

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

这是现在显示的内容-

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

我想展示什么-

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

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

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

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

我怎样才能做到这一点?

【问题讨论】:

    标签: magento navigation layered


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      找到了方法-

      修改了Mage/Catalog/Model/Layer/Filter/Abstract.php 以使用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;
      }
      

      【讨论】:

      • 这是 Mage/Catalog/Model/Layer/Filter/Abstract.php。不是 Mage/Catalog/Layer/Filter/Abstract.php
      猜你喜欢
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2015-10-03
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多