【问题标题】:Reversing the sorting order of the newest product filter in magento颠倒magento中最新产品过滤器的排序顺序
【发布时间】:2017-08-03 05:55:52
【问题描述】:

我使用以下查询向我的 Magento 商店添加了一个最新的过滤器。

UPDATE `catalog_eav_attribute`
SET `used_for_sort_by` = 1
WHERE attribute_id = (SELECT ea.attribute_id FROM `eav_attribute` ea WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") AND `attribute_code` = "created_at")


UPDATE `eav_attribute`
SET frontend_label = "Newest"
WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") and `attribute_code` = "created_at";

排序的过滤器在前端反映,但它显示旧产品在最后,新产品在最后,谁能告诉我如何改变这个排序顺序?

【问题讨论】:

    标签: mysql sorting filter magento-1.9 configurable-product


    【解决方案1】:

    默认按升序排列,你可以在设置集合之前从文件中更改它:app/code/core/Mage/Catalog/Block/Product/List.php

    protected function _beforeToHtml()
    {
        $toolbar = $this->getToolbarBlock();
    
        // called prepare sortable parameters
        $collection = $this->_getProductCollection();
    
        // use sortable parameters
        if ($orders = $this->getAvailableOrders()) {
            $toolbar->setAvailableOrders($orders);
        }
        if ($sort = $this->getSortBy()) {
            $toolbar->setDefaultOrder($sort);
        }
        if ($dir = $this->getDefaultDirection()) {
            $toolbar->setDefaultDirection($dir);
        }
        if ($modes = $this->getModes()) {
            $toolbar->setModes($modes);
        }
    
        /************  Our Condition   ***********/
        if($sort == 'created_at'){
           $toolbar->setDefaultDirection('desc');
        }
    
        // set collection to toolbar and apply sort
        $toolbar->setCollection($collection);
    

    并确保在进行更改之前覆盖此文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 2011-04-19
      相关资源
      最近更新 更多