您可以通过Mage_Reports_Model_Resource_Product_Collection模型获取视图计数.
// 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);
集合中的每个项目都是具有views属性集的目录/产品实例,因此您可以使用$product-> getViews()来获取计数.
如果您不想加载整个产品模型并且只需要查看计数,则可以这样:
$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);
这为您提供了一个数组,键是产品ID,值是视图计数.
原文地址:https://www.jb51.cc/php/135877.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。