Not Getting most popular products .I have category in which most popular product will list down. What i did

Create a CMS Block

{{block type="catalog/product_mostviewed" template="catalog/product/viewed.phtml"}}



<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
<div class=" most_viewed">
<div class="mv_title"><?php echo $this->__('These Products Are Popular Right Now!') ?></div>
<?php $_collectionSize = 5;//count($_products->getItems()); echo $_collectionSize; ?>
<ul class="products-grid" id="products-grid-table">
<?php $i=1; foreach ($_products->getItems() as $_product): ?>
    <li id="td_<?php echo $i;?>" <?php if($i%5==0 or $i==$_collectionSize){echo 'class="last"';} ?> >
        <div id="cont_<?php echo $i;?>">        
            <a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
            <div class="a-center">                        
                <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                <?php if($_product->isSaleable()): ?>
                    <button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
                    <div class="clear"></div>
                <?php else: ?>
                    <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span></p>
                    <div class="clear"></div>
                <?php endif; ?>
                <ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                    <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                    <li class="last"><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
<?php $i++; endforeach; $kol = $_collectionSize; ?>
<?php endif; ?>

2 Answers 2


This happens because the block with type catalog/product_mostviewed does not exist in Magento. If you created the block make sure you did it right. Check you var/log folder for errors.

If you really want to see if the action of viewing a product is registered look in the database in table report_event. Search for records with event_type_id = 1. If there are such records it means the event is tracked.
There is an other chance that you don't see any product because a refresh to the statistics is needed (Reports->Refresh statistics).

  • Check Step 3 : [link]blog.magikcommerce.com/… Apr 8, 2013 at 12:27
  • The tutorial you suggested worked perfectly. this means you are doing something wrong. I updated the answer, maybe that helps.
    – Marius
    Apr 8, 2013 at 12:44
  • Not working for me. i am following exact the same steps. also checked the report_event. its is tracking records. Apr 10, 2013 at 8:51

added the following code:

class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract
    public function __construct(){
        $storeId = Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('reports/product_collection')
        $collection->getSelect()->joinInner(array('e2' => 'catalog_product_flat_'.$storeId), 'e2.entity_id = e.entity_id');

    protected function _prepareLayout()

        $toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', microtime())

        $pager = $this->getLayout()->createBlock('page/html_pager', microtime());
        $toolbar->setChild('product_list_toolbar_pager', $pager);

        $this->setChild('toolbar', $toolbar);

        return $this;

    public function getPagerHtml()
        return $this->getChildHtml('toolbar');

Your template should be like this:

<?php $_collection = $this->getProductCollection(); ?>

<!-- top pagination -->
<?php echo $this->getPagerHtml(); ?>

<?php if($_collection->getSize()): ?>
    <?php foreach ($_collection as $_item): ?>
    <?php endforeach; ?>
<?php endif ?>

<!-- bottom pagination -->
<?php echo $this->getPagerHtml(); ?>

Good luck for you!

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.