如何让 Magento 按添加日期对目录中的产品进行排序?这不是管理员中的一个选项,因此猜测需要在代码中的某个位置完成。
谢谢。
最佳答案
如果您同意(您不应该)修改核心文件,那么添加按日期排序选项非常容易。只需修改 app/code/core/Mage/Catalog/Model/Config.php 文件,如下例所示:
public function getAttributeUsedForSortByArray()
{
$options = array(
'position' => Mage::helper('catalog')->__('Position'),
// HERE IS OUR NEW OPTION
'created_at' => Mage::helper('catalog')->__('Date')
);
foreach ($this->getAttributesUsedForSortBy() as $attribute) {
/* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
$options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
}
return $options;
}
<小时/>
如果您不喜欢修改核心文件,那么这并不容易。在这种情况下,您必须创建这堆文件:
app/etc/modules/Stackoverflow_Catalog.xml
<?xml version="1.0"?>
<config>
<modules>
<Stackoverflow_Catalog>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</Stackoverflow_Catalog>
</modules>
</config>
app/code/local/Stackoverflow/Catalog/etc/config.xml
<?xml version="1.0"?>
<config>
<global>
<models>
<catalog>
<rewrite>
<config>Stackoverflow_Catalog_Model_Config</config>
</rewrite>
</catalog>
</models>
</global>
</config>
app/code/local/Stackoverflow/Catalog/Model/Config.php
<?php
class Stackoverflow_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;
}
}
提示:采取干净的方式,从长远来看,它会带来返回。
关于Magento - 按添加日期排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2237513/