0

我想默认显示我所有的产品,从最新到最旧。我看到了这个链接:

第一个解决方案

第二种解决方案

还有这个。它们都显示相同的解决方案,但总是针对前端。

我想要的是在System->Configuration->Catalog->Product Listing 上默认设置排序方式并将其默认设置为Created at,我还想设置顺序(desc 或 asc)。

关于如何定制的任何想法?

4

3 回答 3

3

很抱歉我没有回答你的问题。

网格按 entity_id 排序:

// app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php:41
$this->setDefaultSort('entity_id');
$this->setDefaultDir('DESC');

这意味着,您想要的行为应该是默认的。

于 2012-12-28T09:49:48.250 回答
2

您可以安装GridControl并编写一个扩展并将其添加到您在模块中创建的 grid.xml

<?xml version="1.0"?>
<gridcontrol>
    <grids>
        <product.grid>
            <add>
                <header>Created at</header>
                <type>int</type>
                <index>created_at</index>
          </add>        
        </product.grid>
    </grids>
</gridcontrol>

此解决方案未经测试。

于 2012-12-26T18:20:17.510 回答
0

在不更改任何核心文件的情况下进行此操作的最佳方法是复制位于以下位置的 Toolbar.php 文件:

/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

然后在下面创建一个新的目录路径(如果你还没有创建一个):

/app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

现在从第 232 行替换以下内容:

    if ($this->getCurrentOrder()) {
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }

if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='position'){ //defines the sort option
//sort by position (ascending) and entity_id (descending)
$this->_collection->addAttributeToSort('position','asc')->addAttributeToSort('entity_id','desc');
} else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}

最后,在您的 Magento 后端重新索引和刷新缓存并准备就绪。

于 2015-10-22T13:24:39.480 回答