2017-08-03 80 views
0

我使用以下查詢爲我的Magento商店添加了一個最新過濾器。逆轉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"; 

排序的過濾器是反映在前端,但它首先顯示舊產品和新產品在過去,誰能告訴我怎樣才能改變這種排序順序?

回答

0

默認情況下它會被歸類爲升,你可以從文件改成:應用程序/代碼/核心/法師/目錄/座/產品/ 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); 

,做確保在進行更改之前覆蓋此文件。