2

正如标题所示,我如何在 Magento 中获取特定产品的查看次数/点击次数/印象数。欢迎任何帮助。

4

2 回答 2

6

这个简单的示例将为您提供在您指定的日期之间查看过的产品列表 + 他们的查看次数:

$fromDate = '2010-01-01';
$toDate   = now();

$viewedProducts = Mage::getResourceModel('reports/product_collection')
                ->addViewsCount($fromDate, $toDate);

foreach($viewedProducts as $product) {
    echo "ID: " . $product->getData('entity_id') . " - View Count: " . $product->getData('views') . "<br/>";
}
于 2012-06-08T08:27:11.810 回答
0

它帮助了我,仅获得一种产品的浏览量。

$resource = Mage::getResourceModel('reports/event');

$select = $resource->getReadConnection()->select()
    ->from(array('ev' => $resource->getMainTable()), array(
        'product_id' => 'object_id',
        'view_count' => new Zend_Db_Expr('COUNT(*)')
     ))
     ->join(
          array('et' => $resource->getTable('reports/event_type')),
                "ev.event_type_id=et.event_type_id AND et.event_name='catalog_product_view'",'')
     ->group('ev.object_id')
     ->where('ev.object_id IN(?)', [$entity_id])
     ->where('ev.logged_at >= ?', $from)
     ->where('ev.logged_at <= ?', $to);
$views = $resource->getReadConnection()->fetchPairs($select);
$views = !empty($views[$entity_id]) ? $views[$entity_id] : 0;
于 2017-08-01T19:52:52.550 回答