Php 如何像magento中的产品一样获得productlist页面视图计数?

Php 如何像magento中的产品一样获得productlist页面视图计数?,php,magento-1.9,Php,Magento 1.9,我可以在magento 1中获得product/list.php视图计数,如product/view.php 要查看列表页面的浏览次数?您可以通过Mage\u Reports\u Model\u Resource\u Product\u CollectionModel获取浏览次数。 集合中的每一项都是一个带有视图属性集的目录/产品实例,因此您可以使用$product->getViews()获取计数 如果您不想加载整个产品模型,而只需要查看计数,则可以如下所示: $resource=Mage:

我可以在magento 1中获得
product/list.php
视图计数,如
product/view.php


要查看列表页面的浏览次数?

您可以通过
Mage\u Reports\u Model\u Resource\u Product\u Collection
Model获取浏览次数。

集合中的每一项都是一个带有视图属性集的
目录/产品
实例,因此您可以使用
$product->getViews()
获取计数

如果您不想加载整个产品模型,而只需要查看计数,则可以如下所示:

$resource=Mage::getResourceModel('reports/event');
$select=$resource->getReadConnection()->select()
->从(数组('ev'=>$resource->getMainTable()),数组(
“产品标识”=>“对象标识”,
'view_count'=>new Zend_Db_Expr('count(*)'))
))
//加入目录\产品\视图的事件类型id
->加入(
数组('et'=>$resource->getTable('reports/event_type')),
“ev.event\u type\u id=et.event\u type\u id和et.event\u name='catalog\u product\u view',
''
)
->组('ev.object\u id')
//添加所需的过滤器
->其中('ev.object_id IN(?),productId)
->其中('ev.logged_at>=?',$from)

->在哪里('ev.logged_at Yes you can.:)您能告诉我怎么做吗?根据我们的指导原则:“要求我们推荐或查找书籍、工具、软件库、教程或其他非现场资源的问题对于堆栈溢出来说是离题的,因为它们往往会吸引自以为是的答案和垃圾邮件。相反,请描述问题以及迄今为止为解决它所做的工作。”-不,我不能。打开谷歌搜索,你可以找到你要找的。5分钟内就完成了。
// set $to and $from to an empty string to disable time range filtering
$from = '2012-01-01';
$to = now();
$productIds = array(9, 35); // your product ids, (works as an int, too) 

$reports = Mage::getResourceModel('reports/product_collection')
    ->addViewsCount($from, $to)
    ->addFieldToFilter('entity_id', $productIds);
$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 for the event type id of catalog_product_view
    ->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')

    // add required filters
    ->where('ev.object_id IN(?)', productIds)
    ->where('ev.logged_at >= ?', $from)
    ->where('ev.logged_at <= ?', $to);

$result = $resource->getReadConnection()->fetchPairs($select);