排序问题

    xiaoxiao2021-03-25  128

    实际应用中相同的排序比较多,比如排序都是数字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

    转载请注明原文地址: https://ju.6miu.com/read-4004.html

    最新回复(0)