0

如何在 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}

当我使用上面的代码时,页面显示空白屏幕。

什么问题?

谢谢,卡西克

4

2 回答 2

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;
    }
于 2013-06-01T05:10:26.353 回答
-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; 
    }
    
  2. 编辑/thems/your-theme/products.tpl

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

解决了PS 1.5.6.1

收集所有访问您页面的访问者。请访问此产品页面

于 2014-12-29T02:52:53.347 回答