Jump to content

Display in product page how many times item have been viewed


Recommended Posts

Can somebody tell me how to make display in product page how many times item have been viewed by customers, there is module best products but it just for backend, I want it in main page.

Share this post


Link to post
Share on other sites
  • 3 months later...
  • 3 months later...

in Product.php class add function
 

    public static 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;
	}

then in product.tpl file you can use:

{Product::getTotalViewed1(Tools::getValue('id_product'))}

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More