Monday, December 28, 2015

Get BestSeller Products In Magento.
In this toturial we simple get the bestseller product on home page in mgento.
In this process we are simple creating the phtml file in temple/catalog/product/bestseller.phtml file. After  that we type the some code foe getting bestseller product.
 <?php
 $productCount = 5;
        $storeId    = Mage::app()->getStore()->getId();
$productsBestSellerMens = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->addAttributeToSelect('*') 
            ->setStoreId($storeId)
            ->setPageSize($productCount);
foreach($productsBestSellerMens as $pro)
{
echo $pro->getDescription();
                                 //also getShortDescription
                                   echo '$'.$pro->getPrice();
                                 echo $this->getAddToCartUrl($pro);
<a href="<?php echo $pro->getProductUrl();?>">
                                 
                                 <img src="<?php echo $this->helper('catalog/image')->init($pro, 'small_image')->resize(200,200); ?>" alt="<?php echo $this->htmlEscape($pro->getName()) ?>"/>
                                 </a>
                                 <p class="action"><button type="button" title="<?php echo $this->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($pro); ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
Then save this file .
After that go to admin panel and open the home page from the cms page .
And type the below code in content part of the homepage.
{{block type="catalog/product" template="catalog/product/bestseller.phtml"}}
After that save the page  and goto home page. You se the bestseller product on home page.

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...