如何在magento的左栏显示最新,最高评价和最好的产品

Ara*_*asu 3 magento

我正在使用Magento ver.1.5.0.1.在主页我用左栏2列.我想一个接一个地展示最新,最高评价和最好的产品.请帮我怎么做.我是magento的新手,请帮助我......

use*_*772 13

在您的app/design/frontend/{your-interface}/{your-theme} /template/catalog/navigation/left.phtml中,为最新产品添加以下代码:

<?php

$_productCollection = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')
                    ->setVisibility(array(2,3,4))                   
                    ->setOrder('created_at', 'desc')
                    ->setPage(1, 5);
?>

<h2>Latest Products</h2>
<ul>
<?php foreach($_productCollection as $_product) : ?>
 <li><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)

评价最高的产品有点复杂.使用以下代码:

<?php

$_productCollection = Mage::getResourceModel('reports/product_collection')
                   ->addAttributeToSelect('*')
                   ->setVisibility(array(2,3,4));

$_productCollection->joinField('rating_summary', 'review/review_aggregate', 'rating_summary', 'entity_pk_value=entity_id',  array('entity_type' => 1, 'store_id' => Mage::app()->getStore()->getId()), 'left');                
$_productCollection->setOrder('rating_summary', 'desc');
$_productCollection->setPage(1, 5);

?>

<h2>Latest Products</h2>
<ul>
<?php foreach($_productCollection as $_product) : ?>
 <li><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)

不确定你最好的产品是什么意思,但如果畅销书,这里是代码:

<?php

$_productCollection = Mage::getResourceModel('reports/product_collection')
                   ->addAttributeToSelect('*')
                   ->setVisibility(array(2,3,4));

$select = $_productCollection->getSelect();

$sqlSelectColumns =  $select->getPart('columns');
$sqlSelectColumns[] = array(
            '',
            new Zend_Db_Expr('(
                SELECT SUM(order_item.qty_invoiced - order_item.qty_refunded)
                FROM ' . Mage::getSingleton('core/resource')->getTableName('sales/order_item') . ' AS order_item
                WHERE order_item.product_id = e.entity_id)
            '),
            'ordered_qty'
        );
$select->setPart('columns', $sqlSelectColumns);

$_productCollection->setOrder('ordered_qty', 'desc');
$_productCollection->setPage(1, 5);

?>

<h2>Top Selling Products</h2>
<ul>
<?php foreach($_productCollection as $_product) : ?>
 <li><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></a></li>
<?php endforeach; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)