排序问题

来源:互联网 发布:电气原理图 软件 编辑:程序博客网 时间: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