在产品列表页面中按最新,折扣,最畅销,评论对产品进行排序


10

在产品列表页面上,我们可以像默认的Magento一样按“位置,名称,价格”进行排序。

如何排序

  1. 最新产品(最近上传)
  2. 折扣(最高折扣产品优先)
  3. 畅销书(最畅销的产品排在首位)
  4. 评论(高分产品首先显示)

如果您需要任何说明,请告诉我...

Answers:


7

对于-> 最近查看的内容,请参见此处

->按评分排序

复制文件

app/code/core/Mage/Catalog/Block/Product/List.php

app/code/local/Mage/Catalog/Block/Product/List.php

list.php寻找这条线

$this->_productCollection =$layer->getProductCollection();

这将在附近line no 86添加以下代码

$this->_productCollection->joinField('rating_summary', 'review_entity_summary', 'rating_summary', 'entity_pk_value=entity_id', array('entity_type'=>1, 'store_id'=> Mage::app()->getStore()->getId()), 'left')

现在复制

app/code/core/Mage/Catalog/Model/Config.php

app/code/local/Mage/Catalog/Model/Config.php

在config.php中找到此代码

$options = array(
    'position'  => Mage::helper('catalog')->__('Position')
);

用。。。来代替

$options = array(
    'position'  => Mage::helper('catalog')->__('Position'),
    'rating_summary' => Mage::helper('catalog')->__('Rating')
);

->>为 BESTSELLER

遵循此过程创建一个文件夹命名,Inchoo并在该文件夹中Catalog和目录中创建3个文件夹Blocketc然后ModelBlockadd ProductProduct添加List并在List文件中创建并命名为,Toolbar.php并将此代码添加到其中

<?php
class Inchoo_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{
    public function setCollection($collection)
    {
        parent::setCollection($collection);

        if ($this->getCurrentOrder()) {
            if($this->getCurrentOrder() == 'qty_ordered') {
                $this->getCollection()->getSelect()
                     ->joinLeft(
                            array('sfoi' => $collection->getResource()->getTable('sales/order_item')),
                             'e.entity_id = sfoi.product_id',
                             array('qty_ordered' => 'SUM(sfoi.qty_ordered)')
                         )
                     ->group('e.entity_id')
                     ->order('qty_ordered ' . $this->getCurrentDirection());
            } else {
                $this->getCollection()
                     ->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())->getSelect();
            }
        }

        return $this;
    }
}

现在在etc文件夹中创建一个名称为的文件config.xml并添加此代码

<config>
    <modules>
        <Inchoo_Catalog>
            <version>0.1.0</version>
        </Inchoo_Catalog>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                    <product_list_toolbar>Inchoo_Catalog_Block_Product_List_Toolbar</product_list_toolbar>
                </rewrite>
            </catalog>
        </blocks>
        <models>
            <catalog>
                <rewrite>
                    <config>Inchoo_Catalog_Model_Config</config>
                </rewrite>
            </catalog>
            <catalog_resource>
                <rewrite>
                    <product_collection>Inchoo_Catalog_Model_Resource_Product_Collection</product_collection>
                </rewrite>
            </catalog_resource>
        </models>
    </global>
</config>

现在,Model创建一个文件命名Config.php并添加此代码。

<?php class Inchoo_Catalog_Model_Config extends Mage_Catalog_Model_Config
{
    public function getAttributeUsedForSortByArray()
    {
        return array_merge(
            parent::getAttributeUsedForSortByArray(),
            array('qty_ordered' => Mage::helper('catalog')->__('Sold quantity'))
        );
    }
}

还可以在文件Resource夹内ModelResource文件夹内创建Product文件夹中创建文件夹,并创建文件命名Collection.php并添加以下代码。

<?php
class Inchoo_Catalog_Model_Resource_Product_Collection extends Mage_Catalog_Model_Resource_Product_Collection
{
    protected function _getSelectCountSql($select = null, $resetLeftJoins = true)
    {
       $this->_renderFilters();
       $countSelect = (is_null($select)) ?
           $this->_getClearSelect() :
           $this->_buildClearSelect($select);

       if(count($countSelect->getPart(Zend_Db_Select::GROUP)) > 0) {
           $countSelect->reset(Zend_Db_Select::GROUP);
       }

       $countSelect->columns('COUNT(DISTINCT e.entity_id)');
       if ($resetLeftJoins) {
           $countSelect->resetJoinLeft();
       }
       return $countSelect;
    }
}

现在,最后通过app/etc/modules创建文件并Inchoo_Catalog.xml添加此代码来激活该模块。

<?xml version="1.0"?>
<!--
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Connect
 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
-->
<config>
    <modules>
        <Inchoo_Catalog>
            <active>true</active>
            <codePool>community</codePool>
            <depends />
        </Inchoo_Catalog>
    </modules>
</config>

并且SALE我建议你这个扩展名,因为我无法找到任何编程的方式来实现这一目标。


您好,非常感谢答复,我将检查并尽快告诉你....
在Magento婴儿

在产品列表页面的“排序依据”中,我还有什么要做的事情?排序在产品列表页”:我做缓存和索引管理,但是评级选项未下显示。
在Magento婴儿

pastebin.com/5403TsLa => list.php的 pastebin.com/Z7WK7C1m => config.php文件请上述文件....
婴儿在Magento

嗯,代码对我来说很好用,我不明白您的问题是什么
dh47 2014年

我会再次检查....
婴儿在Magento
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.