Magento - 按添加日期排序

标签 magento

如何让 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/

相关文章:

magento - 如何在magento主页显示产品描述

magento - 如何在 Magento 的灯箱弹出窗口中显示时事通讯注册?

ruby - 如何通过 Magento SOAP API 使用 savon gem

Magento 缓存 - 关于 Varnish、Redis、APC、Memcache 的困惑

magento - 获取 bundle 产品的单个选项 ID

javascript - Magento 菜单上的自定义 javascript

Magento 1.7 向集合过滤器添加多个属性

php - Magento - 购物车未显示且结帐/购物车页面为空(不显示 .cart div)

Magento Cron Job 意外行为

php - Magento 文件夹更改