Jump to content

[SOLVED]Page statistic get views numbers of products!


Recommended Posts

I am trying for one day now to get statistics on the page like how many views has a products - i was able to get this code this now:

{php}

    function getTotalViewed1($id_product)
   {
       $view2 = Db::getInstance()->getRow('
       SELECT SUM(pv.`counter`) AS total
       FROM `'._DB_PREFIX_.'page_viewed` pv
       LEFT JOIN `'._DB_PREFIX_.'date_range` dr ON pv.`id_date_range` = dr.`id_date_range`
       LEFT JOIN `'._DB_PREFIX_.'page` p ON pv.`id_page` = p.`id_page`
       LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`
       WHERE pt.`name` = \'product.php\'
       AND p.`id_object` = '.intval($id_product).'');
       return isset($view2['total']) ? $view2['total'] : 0;
   }

$totalViewed_1 = getTotalViewed1($product->id);
echo $totalViewed_1;
{/php}



Its freaking strange , it's exactly the same code that tell us how many visits a product has , why is not working i think it has something to do with this bit of code

WHERE pt.`name` = \'product.php\'

because if i take this code out it shows the stats for all products not one.

Thanks!

Link to comment
Share on other sites

So this is the code that will show product views. You can simply add this code on your theme folder in product.tpl - anywhere u like. assign it to smarty or use it with {php}{/php} . I used it this way because i want to easily find the code i added. its better for the day i will upgrade!

{php}

    function getTotalViewed1($id_product)
   {
       $view1 = Db::getInstance()->getRow('
       SELECT SUM(pv.`counter`) AS total
       FROM `'._DB_PREFIX_.'page_viewed` pv
       LEFT JOIN `'._DB_PREFIX_.'date_range` dr ON pv.`id_date_range` = dr.`id_date_range`
       LEFT JOIN `'._DB_PREFIX_.'page` p ON pv.`id_page` = p.`id_page`
       LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type`
       WHERE pt.`name` = \'product.php\'
       AND p.`id_object` = '.intval($id_product).'');
       return isset($view1['total']) ? $view1['total'] : 0;
   }

       if ($id_product = intval(Tools::getValue('id_product')))
       {
           $product = new Product($id_product, false, intval($cookie->id_lang));
           $totalViewed1 = getTotalViewed1($product->id);
           echo $totalViewed1;            
               }

{/php}

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 1 year later...
  • 1 year later...
  • 1 year later...

1. edit     classes/Controller/FrontController.php

public static function getTotalViewed($id_product){ 

                 $view1 = Db::getInstance()->getRow('SELECT SUM(pv.counter) AS total FROM '._DB_PREFIX_.'page_viewed pv 
                  LEFT JOIN '._DB_PREFIX_.'page p ON pv.id_page = p.id_page 
                  LEFT JOIN '._DB_PREFIX_.'page_type pt ON p.id_page_type = pt.id_page_type 
                  WHERE pt.name = \'product\' AND p.`id_object` = '.intval($id_product).' group by pv.id_page'); 
                  return isset($view1['total']) ? $view1['total'] : 0; 
}

 

2. edit     /thems/your-theme/products.tpl

{FrontController::getTotalViewed(Tools::getValue('id_product'))}

 

solved PS 1.5.6.1

 

Collect all your visitor that visit your page . pls visit this product pages 7zhop.com

Edited by fong hong (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...