Magento 按实体 ID 降序排序


Magento Sort By Entity ID Descending

我希望修改默认的Magento(1.6)目录排序以添加按产品实体ID排序的选项,然后将其设置为默认排序。

(在StackOverflow和Google上搜索了所有内容,但只能找到适用于旧版Magento或编辑核心文件的解决方案。

提前感谢!

这篇 http://blog.chapagain.com.np/magento-join-filter-select-and-sort-attributes-fields-and-tables/是一篇很好的文章,它提供了有关如何过滤和排序集合的信息。

在不更改任何核心文件的情况下执行此操作的最佳方法是复制工具栏.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 entity_id (descending)
$this->_collection->addAttributeToSort('entity_id','desc');
} else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}

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