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; }
source share