如何在magento的左侧栏中显示最新,最受好评的产品和最佳产品 [英] how to show latest,top rated and best products in left bar in magento

查看:71
本文介绍了如何在magento的左侧栏中显示最新,最受好评的产品和最佳产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Magento版本. 1.5.0.1.在首页中,我使用了2列,并带有左栏.我想展示一个最新,最受好评的最佳产品.请帮我怎么做.我是magento的新手,请帮助我....

i'm using Magento ver. 1.5.0.1. In homepage i used 2 columns with left bar. i want to show latest,top rated and best products one below the other. please help me how to do this. i'm new to magento please help me....

推荐答案

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

In your app/design/frontend/{your-interface}/{your-theme}/template/catalog/navigation/left.phtml add the following code for latest products:

<?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>

最受好评的产品要复杂一些.使用以下代码:

The top rated products are a bit more complicated. Use the following code:

<?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>

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

Not sure what you meant by the best products but if bestsellers, here is the code for that:

<?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>

这篇关于如何在magento的左侧栏中显示最新,最受好评的产品和最佳产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆