0

prestashop で製品ビュー数を取得する方法。

私のコードは

\themes\default\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 に答える