u want to display the best selling products in your Magento store on the frontpage or anywhere else in your store? i found this snippets @MagentoForum, it’s easy to use…
[Step 1] Create a Bestseller.php file and put it here :
app/code/local/Mage/Catalog/Block/Product/Bestseller.php
class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract{ public function __construct(){ parent::__construct(); $storeId = Mage::app()->getStore()->getId(); $products = Mage::getResourceModel('reports/product_collection') ->addOrderedQty() ->addAttributeToSelect('*') ->addAttributeToSelect(array('name', 'price', 'small_image')) ->setStoreId($storeId) ->addStoreFilter($storeId) ->setOrder('ordered_qty', 'desc'); // most best sellers on top Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products); $products->setPageSize(3)->setCurPage(1); $this->setProductCollection($products); } }
[Step 2] Create a bestseller.phtml file and put it here :
app/design/frontend/*/*/template/catalog/product/bestseller.phtml
getProductCollection()) && $_products->getSize()): ?>getItems()) ?>__('Best Seller Products') ?>
>htmlEscape($_product->getName()) ?> getRatingSummary()): ?> getReviewsSummaryHtml($_product, 'short') ?> getPriceHtml($_product, true) ?> isSaleable()): ?> __('Out of stock') ?>
|
[Step 3] now put this line where you want to view best selling products..
{{block type="catalog/product_bestseller" template="catalog/product/bestseller.phtml"}}
Source : http://harisur.net/how-to-get-best-selling-product-in-magento