开发者

how to show latest,top rated and best products in left bar in 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....


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>


This extesnsion is very helpfull for your requirement. You can install this extension from url : http://www.magentocommerce.com/magento-connect/mageoutsourcing/extension/6669/bnm

After installation in your magento, a little chage into xml which helps to display best selling product in the left side of other. You should change layout xml from :

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="right">
            <block type="bnm/bestsellingproduct" name="bestsellingproduct.sidebar" after="cart_sidebar" template="bnm/bestselling-sidebar.phtml"/>          
        </reference>
    </default>    
</layout>

To :

<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
        <reference name="left">
            <block type="bnm/bestsellingproduct" name="bestsellingproduct.sidebar" after="-" template="bnm/bestselling-sidebar.phtml"/>         
        </reference>
    </default>    
</layout> 

NOTE : before (and) after – These are two ways to position a content block within a structural block. before="-" and after="-" are commands used to position the block accordingly at the very top or very bottom of a structural block.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜