I created a extension for displaying Most viewed products in home page. I am able to see the products but there is no name or image and the price is displayed as $0.0. I am not able to figure out the reason for why the products are displayed in this way.

Please help me

enter image description here

Code in Block file:

        $storeId    = Mage::app()->getStore()->getId();
        $products = Mage::getResourceModel('reports/product_collection')  
            ->addAttributeToSelect(array('name', 'price', 'small_image'))



        $this->_productCollection = $products;

//die(); return $this->_productCollection;

Code in phtml file:

<?php echo $this->getLayout()->createBlock('catalogextensions/mostviewed_home_list')->setTemplate('catalog/product/list.phtml')->toHtml(); ?>
  • 1
    please put your code?
    – Amit Bera
    Nov 19, 2014 at 12:16
  • Wild guess: you did not specify the attributes to load with the product collection. Nov 19, 2014 at 12:23
  • I have added the code in the question..
    – Stalin
    Nov 19, 2014 at 12:25

1 Answer 1


Using my psychic powers I see that you did retrieve the collection like this:

$collection = Mage::getResourceModel('reports/product_collection')->addViewsCount()....;

and you forgot to add any attributes to the collection.
You should do something like this:

$collection = Mage::getResourceModel('reports/product_collection')->addViewsCount()
//   ...other filters here

Ah...my psychic powers are failing me. You did add them. But you added the addViewsCount at the end. That method resets the select. You need to add the attributes after calling addViewsCount

  • your psychic power is so strength :-) File: app/code/core/Mage/Reports/Model/Resource/Product/Collection.php:365 "$this->getSelect()->reset()"
    – roman204
    Nov 19, 2014 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.