排序问题
来源:互联网 发布:电气原理图 软件 编辑:程序博客网 时间:2024/05/23 18:42
实际应用中相同的排序比较多,比如排序都是数字2,导致每次刷新页面出来的列表都不一样,解决这个问题需要加第二位的排序来辅助
app\code\core\Mage\Catalog\Model\Resource\Product\Collection.php
/** * Add attribute to sort order * * @param string $attribute * @param string $dir * @return Mage_Catalog_Model_Resource_Product_Collection */ public function addAttributeToSort($attribute, $dir = self::SORT_ORDER_ASC) { if ($attribute == 'position') { if (isset($this->_joinFields[$attribute])) { $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir); return $this; } if ($this->isEnabledFlat()) { $this->getSelect()->order("cat_index_position {$dir}"); } // optimize if using cat index $filters = $this->_productLimitationFilters; if (isset($filters['category_id']) || isset($filters['visibility'])) { $this->getSelect()->order('cat_index.position ' . $dir); $this->getSelect()->order('e.entity_id ' . self::SORT_ORDER_DESC); } else { $this->getSelect()->order('e.entity_id ' . $dir); } return $this; } elseif($attribute == 'is_saleable'){ $this->getSelect()->order("is_saleable " . $dir); return $this; } $storeId = $this->getStoreId(); if ($attribute == 'price' && $storeId != 0) { $this->addPriceData(); $this->getSelect()->order("price_index.min_price {$dir}"); return $this; } if ($this->isEnabledFlat()) { $column = $this->getEntity()->getAttributeSortColumn($attribute); if ($column) { $this->getSelect()->order("e.{$column} {$dir}"); } else if (isset($this->_joinFields[$attribute])) { $this->getSelect()->order($this->_getAttributeFieldName($attribute) . ' ' . $dir); } return $this; } else { $attrInstance = $this->getEntity()->getAttribute($attribute); if ($attrInstance && $attrInstance->usesSource()) { $attrInstance->getSource() ->addValueSortToCollection($this, $dir); return $this; } } return parent::addAttributeToSort($attribute, $dir); }\lib\Varien\Db\Adapter\Pdo\Mysql.php
以下改了不起作用
\app\code\core\Mage\Catalog\Model\Config.php
/** * Retrieve Attributes Used for Sort by as array * key = code, value = name * * @return array */ public function getAttributeUsedForSortByArray() { $options = array( 'position' => Mage::helper('catalog')->__('Position'), '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; }
http://stackoverflow.com/questions/2237513/magento-sort-by-date-added
0 0
- 排序问题-归并排序
- 排序问题-快速排序
- 【排序问题】选择排序
- 排序问题
- 排序 问题
- 排序问题
- 排序问题~~
- 排序问题
- 排序问题
- 排序问题
- 排序问题
- 排序问题
- 排序问题
- 排序 问题
- 排序问题
- 排序问题
- 排序问题
- 排序问题
- XtraBackup安装部署与使用 【转】
- 0-1背包问题(回溯物品类)
- iOS CGContextRef详解与使用
- 企业 SOA 设计–ESB 设计
- Java高并发程序设计笔记(七)锁的优化
- 排序问题
- 2. Add Two Numbers
- select级联带出数据
- android ListView的常用事件
- android ListView的常用事件
- Hibernate框架使用步骤
- 史上最全的MonkeyRunner自动化测试从入门到精通(3)
- frameset框架左侧菜单(加点击变色)
- 顺序表的基本操作