Magento产品按销量排行How to sort/show products by sold quantity in Magento

Toolbar.php file location:
app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

Your _construct() function should be modified to look something like:
[php]
$this->_availableOrder = array(

position’ => $this->__(’Best Value’),

name’ => $this->__(’Name’),

price’ => $this->__(’Price’),

special_price’ =>$this->__(’Special Price’),

‘ordered_qty’ => $this->__(’Quantity soled’),

);

[/php]

Next we open the list.phtml inside /template/catalog/product/ folder. And you need to find the:

[php]

$_productCollection=$this->getLoadedProductCollection();

[/php]

Expression and cut => paste somewhere to the top of the file. Then we
add some additional logic to that same file. So you should write
something like

[php]

// Custom added

$orderFilterType = $this->getRequest()->getParam(’order’);

// Part of original template code, just moved to top of the file
$_productCollection=$this->getLoadedProductCollection();

// Custom added

if(isset($orderFilterType) && $orderFilterType === ‘ordered_qty’) {

$storeId = Mage::app()->getStore()->getId();

$_productCollection = null;

$_productCollection = Mage::getResourceModel(’reports/product_collection’)
->addAttributeToSelect(’*’)

->addOrderedQty()

->setOrder(’ordered_qty’, $this->getRequest()->getParam(’dir’));

}
[/php]
to the top of the list.phtml file.

File list.phtml should consists of two major parts:
•List mode, which starting with comment
•Grid mode, which starting with comment

At the beginning of each part (mode) there is a “foreach” loop like
[php]
<?php foreach ($_productCollection as $_product): ?>

[/php]

What we need to do now is to duplicate entire content inside that
foreach loop and set it in if-else statement where if statement would go
like:

本文隐藏内容 登陆 后才可以浏览

inside the if statement.

标签


Warning: error_log(/www/wwwroot/www.ctrol.cn/wp-content/plugins/spider-analyser/#log/log-0518.txt): failed to open stream: No such file or directory in /www/wwwroot/www.ctrol.cn/wp-content/plugins/spider-analyser/spider.class.php on line 2900