Magento Best selling product at home page

1. Put the following code at home page cms
{{block type="catalog/product_bestsellers" name="home.catalog.product.bestsellers" alias="product_bestsellers" template="catalog/product/bestsellers.phtml"}}
2. Please create “bestsellers.phtml” page on mentioned location.
3. put the following code in this page.
<?php
/**
* @author MagentoPycho <rajen_k_bhtt@hotmail.com>
* GuruWebSoft www.guruwebsoft.com
* */
$visibility     = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);

$storeId        = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty()
->addAttributeToFilter('visibility', $visibility)
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder('ordered_qty', 'desc')
->setPageSize(4);
#echo $_productCollection->getSelect()->__toString();

?>

<div class="bestList">
<ul>
<?php foreach($_productCollection as $product):
?>

<li><a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $product->name ?>">
<img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize(51,51); ?>" alt="<?php echo $product->name ?>" title="<?php echo $product->name ?>"/>
<span class="bestContent">
<span class="bestDesc"><?php echo $product->name ?></span>
<br />
<span class="sale"><?php echo Mage::helper('core')->currency($product->price, true, false); ?></span>
</span></a></li>

<?php endforeach; ?>
</ul>
</div>

Advertisements