Thursday, September 27, 2012

Bestselling Products in Magento

To add a block into Home Page you need to  login into the Magento : CMS > Manage Pages > Home. Then add the following to the Content area:

{{block type=”catalog/product” show_total=”12″ template=”catalog/product/bestseller.phtml”}}

Now put the following code into catalog/product/bestseller.phtml -

   $visibility = array(
        Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
        Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
  );

  $_productCollection = Mage::getResourceModel('reports/product_collection')
                      ->addAttributeToSelect('*')
                      ->addOrderedQty()
                      ->addAttributeToFilter('visibility', $visibility)
                      ->setOrder('ordered_qty', 'desc');
   $totalPerPage = ($this->show_total) ? $this->show_total : 6 ;
   $counter = 1;
Here you have the Best selling Product Collection. Now feel free to manage your Bestseller page with your own Style.