dongwujie7477 2013-08-22 08:48
浏览 21
已采纳

覆盖magento搜索系统以允许随机顺序

I need to find a way to either add another sort order so that I can sort by random or I need to override the core search system to allow me to achieve the same. (or some combination of the two?)

I know that the magento search files are in app/code/core/Mage/CatalogSearch/ but I am unsure as to which files I need to look at changing.

  • 写回答

2条回答 默认 最新

  • du997562 2013-08-22 13:57
    关注

    The file you are looking for is app/code/core/Mage/CatalogSearch/Model/Layer.php. The name of the class is Mage_Catalog_Model_Layer. Inside it you see the function prepareProductCollection($collection).

    I suggest you rewrite this model (see this or this) and override the aforementioned function and add/implement you sorting logic. An example of overriding this function would be

    class XXX_XXX_Model_CatalogSearch_Layer extends Mage_CatalogSearch_Model_Layer
    {
        public function prepareProductCollection($collection)
        {
            parent::prepareProductCollection($collection);
            $collection->addAttributeToSelect('some_attribute');
            $collection->setOrder('some_attribute', 'asc');
            return $this;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法