1

I am using below code for the most viewed products at home page, but My client keep complaining that these products were not updating.

$products = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->addMinimalPrice()
    ->addUrlRewrite()
    ->addTaxPercents()          
    ->addAttributeToSelect(array('name', 'price', 'small_image')) //edit to suit tastes
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount();  

    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
    $products->setPageSize($this->getConfig('qty'))->setCurPage(1);

Please check and let me know what is the error

0

Try This. It's working on my flat catalog

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

$collection = Mage::getResourceModel('reports/product_collection')
              ->addViewsCount();
if (Mage::helper('catalog/product_flat')->isEnabled()) {

$collection->getSelect()->joinInner(array('e2' => 'catalog_product_flat_'.$storeId), 'e2.entity_id = e.entity_id');
}

Your Answer

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

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