如何在prestashop中获取产品视图计数。
我的代码是
\主题\默认\ product.tpl
{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}
当我使用上面的代码时,页面显示空白屏幕。
问题是什么?
谢谢, Karthick
答案 0 :(得分:0)
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;
}
到
public function getTotalViewed($id_product)
{
$dateBetween = ModuleGraph::getDateBetween();
$result = 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).'
AND dr.`time_start` BETWEEN '.$dateBetween.'
AND dr.`time_end` BETWEEN '.$dateBetween.'');
return isset($result['total']) ? $result['total'] : 0;
}
答案 1 :(得分:-1)
编辑类/ 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;
}
编辑/thems/your-theme/products.tpl
{FrontController::getTotalViewed(Tools::getValue('id_product'))}
解决了PS 1.5.6.1
收集访问您网页的所有访问者。请访问此产品页面