方法一: 安装插件 Sort By Date(https://www.magentocommerce.com/magento-connect/sort-by-date.html)

方法二: 非插件

Today I had to change Magento default products list sorting to sort by product’s date. In fact we don’t need to sort by date, just by entity_id which is product ID in Magento world. To accomplish this, we need to edit /app/code/core/Mage/Catalog/Block/Product/List.php

You have to find _beforeToHtml() function and change some things inside. First we need to define all available sorting options:

$orders = array('entity_id' => $this->__('Newest'), 'name' => $this->__('Name'), 'price' => $this->__('Price') );

then remove all getters of default sorting and order, and put those:

$toolbar->setAvailableOrders($orders);
$toolbar->setDefaultOrder('entity_id');
$toolbar->setDefaultDirection('desc');

so finally your _beforeToHtml() should looks like this one:

protected function _beforeToHtml()
{$toolbar = $this->getToolbarBlock();// called prepare sortable parameters$collection = $this->_getProductCollection();// use sortable parameters$orders = array('entity_id' => $this->__('Newest'), 'name' => $this->__('Name'), 'price' => $this->__('Price') );$toolbar->setAvailableOrders($orders);$toolbar->setDefaultOrder('entity_id');$toolbar->setDefaultDirection('desc');if ($modes = $this->getModes()) {$toolbar->setModes($modes);}// set collection to tollbar and apply sort$toolbar->setCollection($collection);$this->setChild('toolbar', $toolbar);Mage::dispatchEvent('catalog_block_product_list_collection', array('collection'=>$this->_getProductCollection(),));$this->_getProductCollection()->load();Mage::getModel('review/review')->appendSummary($this->_getProductCollection());return parent::_beforeToHtml();
}

from:http://www.blastar.biz/2011/07/29/how-to-sort-magento-products-by-date-added-as-default/

原文/转自:Magento: 设置产品列表默认排序方式 How to sort Magento products by date added as default

Magento: 设置产品列表默认排序方式 How to sort Magento products by date added as default相关推荐

  1. Magento 默认排序为最新 How to sort Magento products by date added as default

    Today I had to change Magento default products list sorting to sort by product's date. In fact we do ...

  2. java 默认排序方式_Java Collections.sort()实现List排序的默认方法和自定义方法

    1.java提供的默认list排序方法 主要代码: list list = new arraylist();list.add("刘媛媛"); list.add("王硕&q ...

  3. MyEclipse设置JSP页面默认编码方式

    MyEclipse设置JSP页面默认编码方式以及设置在Java文件中作者.日期等说明 MyEclipse设置JSP页面默认编码方式: windows(窗口)-Preferences(首选项)-MyEc ...

  4. linux命令ls -l的默认排序方式

    差不多快实现完了ls -l,但是在测试阶段发现一个问题,对于包含[a-ZA-Z]之外的字符,系统的排序方式并不一样. 很想了会儿,总算发现原来它的排序方式是无视[a-ZA-Z]之外的字符的 至于怎么发 ...

  5. 如何设置文件的默认打开方式

    Windows如何设置文件的默认打开方式 当使用Windows更新后,系统无法识别已安装的应用程序时,我们就无法为某些格式的文件直接设置文件的默认打开方式. 可以通过如下方式实现对文件的默认打开方式设 ...

  6. 实践致知第7享:Windows如何设置文件的默认打开方式?

    Windows设置文件的默认打开方式有很多种,本文介绍两种方式: 1.右键单击文件,打开方式>选择其他方式,弹出以下对话框,选择"始终使用此应用打开"(有的系统也称为:默认打 ...

  7. 设置软件的默认打开方式

    以WPS设置为PDF默认打开方式举例 前言:为了编辑下载的C++ Primer PDF文档,下载了万兴PDF工具,安装后发现PDF文件的默认打开方式被该软件修改成了万兴,由于它的图标Logo(如下图) ...

  8. 如何设置office2003为默认打开方式

    如何设置office2003为默认打开方式 当系统同时安装 office 2003和 office 2007(或2010)两个版本的 office办公软件的时候,双击打开一个office文档(Word ...

  9. 电脑同时安装了WPS和Office,怎么设置文件的默认打开方式?

    Microsoft Office是微软公司的一款办公软件,学习工作中的必备工具.WPS则是由金山推出的新兴免费国产办公软件,也非常的好用,可以手机.平板.电脑三端同步. WPS的功能相对可能会较多,用 ...

最新文章

  1. windows下给定多个openNi的Uri,匹配与uri对应的Uvc RGB设备
  2. boost::locale::calendar用法的测试程序
  3. python怎么引用多行输入_python调用shell返回两行第二行需要输入密码怎么办?import os os.syst...
  4. 无线网桥的特点及应用方案
  5. python怎么设置颜色深浅变化_机器学习中减弱不同图像数据色调及颜色深浅差异...
  6. php mysql存储中文为空_PHP如何解决MySQL存储数据中文乱码
  7. win11虚拟内存如何设置 Windows11设置虚拟内存的步骤方法
  8. 開源搜索引擎爬蟲_六大開源搜索引擎工具 | 學步園
  9. INSERT INTO SELECT 语句
  10. POJ 2976 裸的01分数规划
  11. php读取excel文件_如何用PHP读取excel文件内容、获取单元格数据
  12. CSS 颜色代码大全 CSS颜色对照表
  13. html小说站源码,读取本地HTML的小说阅读器应用源码项目
  14. if else语句 整除求余运算
  15. Pytorch 小知识点汇总三--numpy数组 求均值,方差,标准差
  16. CentOS6u9 网卡HWADDR和UUID信息重新生成和获取
  17. 计算机网络名称缓存清理,如何清理电脑网络连接缓存
  18. DHTML动态样式的作用
  19. python好学吗一般要学多久-Python好学吗?精通Python需要多长时间?
  20. SpringBoot: 启动Banner在线生成工具

热门文章

  1. Blackboard Fibonacci(CF-217B)
  2. 7.2 MASS批量修改数据(剪切板上传数据)
  3. 3.5 SE93创建自建表事务码
  4. linux内核启动过程5:启动用户空间
  5. windows:QtCreator调用库的方式
  6. Option,Some,None
  7. YARN部件以及执行流程
  8. 操作系统(李治军) L9多进程图像-操作系统最重要的图像
  9. StringUtils详细介绍
  10. [弹性力学]弹力与材力的同一变量的规定正方向的不同导致公式中个别符号不同