1

I am using the below code for get most-viewed product in my store front:

$storeId = Mage::app()->getStore()->getId();
$products = Mage::getResourceModel('reports/product_collection')
    ->addOrderedQty()
    ->addAttributeToSelect('*')
    ->addAttributeToSelect(['name', 'price', 'small_image'])
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

$products->setPageSize(5)->setCurPage(1);
$this->setProductCollection($products);

It's working fine when "Use Flat Catalog Product" is set to no. But when I set "Use Flat Catalog Product" to yes, product name, price and small_image attribute not get in collection.

Please help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.