让Magento 新上传的产品在分类显示最前面?

来源:互联网 发布:淘宝引流宝怎么设置 编辑:程序博客网 时间:2024/05/16 14:59

在实际环境中,会遇到这种情况,每次添加产品后,但在产品显示页面,先添加的总是在前面,后添加的有时需要翻页,才能看到,这是因为magento的产品在列表页默认是按升序排列,也就是说先添加的产品总是显示在最前面,而后面添加的依次在最后。如果我们想把最后添加的产品排在最前面,也即是倒序排列的话,该如何修改呢?
首先打开如下目录文件:
File:/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php,
找到

protected $_direction = ‘asc’;
这个参数就是默认顺序
修改成:
protected $_direction = ‘desc’;
然后保存。 
也可以通过以下方法来思考,Magento每上传一个产品,都会给该产品赋予一个唯一ID值,而ID值的排序都是自加1,所以,显示方式可以根据最后上传的商品,以ID倒序方式进行排序。
同样修改当前的Toolbar.php
找到:

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

改为:

$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())->setOrder('entity_id', 'desc');
0 0
原创粉丝点击