Monday 14 September 2015

Magento Product View Count in Product List Page and Product View Page

Hello

Some Time You Want to display how many time product view count in magento


I am Give Simple Code it can be used in both product list page it can paste in loop then

it will display every product totoal view count. and product view page current product view


$id = $id=$_helper->productAttribute($_product, $_product->getId(), 'id');


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

            foreach($mostviewedProducts as $product) {
if($product->getData('entity_id')==$id)
{
 
    echo $id."<br/>";
    echo $_product->getId()."<br/>";
   echo $product->getData('entity_id')."<br/>";
    echo  "Total View Count: " . $product->getData('views');
}}?>


You can add time duration in

$fromDate = '2013-12-10';
$toDate   = now();

$id = $id=$_helper->productAttribute($_product, $_product->getId(), 'id');


$mostviewedProducts = Mage::getResourceModel('reports/product_collection')->addViewsCount($fromDate,$toDate);

            foreach($mostviewedProducts as $product) {
if($product->getData('entity_id')==$id)
{
 
    echo $id."<br/>";
    echo $_product->getId()."<br/>";
   echo $product->getData('entity_id')."<br/>";
    echo  "Total View Count: " . $product->getData('views');
}}?>


No comments:

Post a Comment

Thank You For Comment