finrodfelegund Posted July 28, 2010 Share Posted July 28, 2010 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 More sharing options...
finrodfelegund Posted July 28, 2010 Author Share Posted July 28, 2010 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 More sharing options...
GS VISION Posted October 19, 2010 Share Posted October 19, 2010 Thanks mates I`ve been looking for this for a looong time! Link to comment Share on other sites More sharing options...
Hacktor Posted October 28, 2010 Share Posted October 28, 2010 I add the code to my products.tpl.But how can I read these stats????I want to see which products have been most viewed... Link to comment Share on other sites More sharing options...
GS VISION Posted October 28, 2010 Share Posted October 28, 2010 Go to Back Office Stats-> Best Products and you can see it there. !It`s only for the period you`ve chosen. There is an addon that makes it for all time you can search for it in the forum. Link to comment Share on other sites More sharing options...
romanotulini Posted November 30, 2011 Share Posted November 30, 2011 It doesnt work in Presta 1.3.7... Any idea? Link to comment Share on other sites More sharing options...
deph Posted January 25, 2013 Share Posted January 25, 2013 thanx a lot!! Link to comment Share on other sites More sharing options...
fong hong Posted December 29, 2014 Share Posted December 29, 2014 (edited) 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 December 29, 2014 by fong hong (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts