我在目录列表中的排序方法中添加了日期。如果我选择按日期排序,则列表按日期排序 - 这很好用。
但是,我应该怎么做才能在目录列表中设置默认的按日期排序(DESC)?
就我而言,不使用这些解决方案:
目录.xml
<action method="setDefaultDirection"><dir>desc</dir></action>
<action method="setDefaultOrder"><field>created_at</field></action>
和:
目录/ block /产品/列表/Toolbar.php
protected $_direction = 'desc';
Magento 版本:1.7.0.2。
编辑:1
我在本地文件夹/app/code/local/SortByDate/中创建了一个新模块。我添加了两个文件。首先/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;
}
}
第二个/etc/config.xml :
<config><global><models><catalog><rewrite><config>SortByDate_Catalog_Model_Config</config></rewrite></catalog></models></global></config>
编辑 2 - 已解决
我修改了这个功能,问题就消失了:)
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;
}
最佳答案
解决了,我修改了这个函数,问题就消失了:)
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;
}
关于magento - 按创建日期订购产品列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13470553/