Order product list by creation date

I added the sort date to the directory list. If I chose to sort by date, the list is sorted by date - this works well. But what should I do to set the default sort by date (DESC) in the directory list? In my case, not working on these solutions: catalog.xml

<action method="setDefaultDirection"><dir>desc</dir></action> <action method="setDefaultOrder"><field>created_at</field></action> 

and:
Catalog / Block / Product / List / Toolbar.php

 protected $_direction = 'desc'; 

Magento Version: 1.7.0.2.

Edit: 1

I created a new module in the local folder / app / code / local / SortByDate /. I added two files. First /catalog/model/Config.php:

 class SortByDate_Catalog_Model_Config extends Mage_Catalog_Model_Config { public function getAttributeUsedForSortByArray() { $options = parent::getAttributeUsedForSortByArray(); if (!isset($options['created_at'])) { $options['created_at'] = Mage::helper('catalog')->__('Date'); } return $options; } } 


and second /etc/config.xml:

  <config><global><models><catalog><rewrite><config>SortByDate_Catalog_Model_Config</config></rewrite></catalog></models></global></config> 

Change 2 - Solved I am changing this function, the problem has disappeared :)

  public function setDefaultOrder($field) { //set default order by date if (isset($this->_availableOrder[$field])) { $this->_availableOrder = array( 'created_at' => $this->__('Date'), 'name' => $this->__('Name'), 'price' => $this->__('Price'), ); $this->_orderField = $field; } return $this; } 
+4
source share
2 answers

Solved, I am changing this function, the problem did not go away :)

  public function setDefaultOrder($field) { //set default order by date if (isset($this->_availableOrder[$field])) { $this->_availableOrder = array( 'created_at' => $this->__('Date'), 'name' => $this->__('Name'), 'price' => $this->__('Price'), ); $this->_orderField = $field; } return $this; } 
+1
source

I had a similar problem, and in order to fix it for all my sites in their pure form, I developed an extension that does the trick.

It is free and fairly easy to install and use. Fell free to download it.

https://magento.mdnsolutions.com/extensions/mdn-sort-by-date.html

Greetings

Renato

0
source

Source: https://habr.com/ru/post/1447181/


All Articles