Sunday, February 19, 2012

Magento Get overall Bestselling Product

Magento Over all best selling Product on Home page
Add new function in files as per the version
- app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers.php
- app/code/core/Mage/Sales/Model/Mysql4/Report/Bestsellers/Collection.php



public function getBestsellingProducts()
{
    // number of products to display
    $productCount = 5;

    // store ID
    $storeId    = Mage::app()->getStore()->getId();    

    // get most viewed products for current category
    $products = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')
                    ->addOrderedQty()
                    ->setStoreId($storeId)
                    ->addStoreFilter($storeId)
                    ->setOrder('ordered_qty', 'desc')
                    ->setPageSize($productCount);

    Mage::getSingleton('catalog/product_status')
            ->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')
            ->addVisibleInCatalogFilterToCollection($products);

    return $products;
}

and call that function you will get all overall Best Selling Product

Hope this may help you

2 comments:

  1. Thank you for the post.
    I'm convinced that bestsellers can boost eCommerce profit and help web shop owner get much money.
    that's why one day i decided to try magento extension. And i didn't disappointedю It works perfect and save me lots of time.
    I created lots of new products blocks, bestsellers and most viewed.

    If anybody is interested you can read about extension which i use http://amasty.com/improved-sorting.html

    I hope this information will be useful for someone.

    Have a nice day,
    Jim

    ReplyDelete

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...