Magento 按创建日期订购产品列表
我正在给目录列表中的排序方法添加日期。若我选择按日期排序,那个么列表就是按日期排序——这很好用。 但是,对于目录列表中的“按日期设置默认排序”(DESC),我应该怎么做? 就我而言,不使用这些解决方案: catalog.xmlMagento 按创建日期订购产品列表,magento,magento-1.7,Magento,Magento 1.7,我正在给目录列表中的排序方法添加日期。若我选择按日期排序,那个么列表就是按日期排序——这很好用。 但是,对于目录列表中的“按日期设置默认排序”(DESC),我应该怎么做? 就我而言,不使用这些解决方案: catalog.xml <action method="setDefaultDirection"><dir>desc</dir></action> <action method="setDefaultOrder"><field&g
<action method="setDefaultDirection"><dir>desc</dir></action>
<action method="setDefaultOrder"><field>created_at</field></action>
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>
解决了,我修改了这个函数,问题消失了:)
我也有类似的问题,为了以一种干净的方式修复我所有网站的问题,我开发了一个扩展来实现这一点 它是免费的,安装和使用都非常简单。免费下载 干杯
Renato您是如何将日期添加到目录列表中的排序方法的
created_at
不是EAV属性,因此我想您没有通过后端执行此操作。请在你的问题中提供更多细节。我为你添加了“编辑:1”段落。你能检查一下吗?顺便说一句,在StackOverflow(S.O.)上,当你发现自己问题的答案独立于S.O.时,一个受鼓励的工作流程是回答并接受自己的答案。它不仅让人们有机会奖励你的好问题和答案,还让未来的人们更容易看到这个问题,并鼓励其他人发布解决方案。
<config><global><models><catalog><rewrite><config>SortByDate_Catalog_Model_Config</config></rewrite></catalog></models></global></config>
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;
}