Friday, April 20, 2012

Retrieve bestsellers

Here is how you can retrieve a list of bestsellers
$collection = Mage::getResourceModel('sales/report_bestsellers_collection')
            ->setModel('catalog/product')
            ->addStoreFilter(Mage::app()->getStore()->getId())//if you want the bestsellers for a specific store view. if you want global values remove this
            ->setPageSize(5)//se there the number of products you want returned
            ->setCurPage(1);
foreach ($collection as $_product){
    $realProduct = Mage::getModel('catalog/product')->load($_product->getProductId());
    //do something with $realProduct;
}
Make sure you refresehd the statistic for bestsellers. Reports->Refresh statistics. Select refresh lifetime statistics for bestsellers. Enjoy.

3 comments:

  1. Hey there,

    I wish there was a contact-me button but I couldnt find it.
    Im wondering if you can help me with magento?
    Im struggling to install some purchased plugins (same error).
    if you can contact me at sandrine at ziller com au
    Cheers

    ReplyDelete
    Replies
    1. if you want to contact me, leave a comment with your e-mail address (I won't publish it) and I will send you an e-mail.

      Marius.

      Delete
  2. Why use a contact me button, simple use a comment form and allow user comment but 1st you approve it than it's show live, so it's a great and totally free of cost..

    Magento Plugins

    ReplyDelete