Możesz uzyskać liczbę wyświetleń za pomocą modelu 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);
Każdy element kolekcji jest catalog/product
wystąpienie z widokiem zestawu właściwości, dzięki czemu można używać $product->getViews()
aby uzyskać zliczania.
Jeśli nie chcesz, aby załadować cały model produktu i wymagają jedynie liczbę wyświetleń, możesz dostać to tak:
$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);
Daje tablicę, klawisze są identyfikatory produktów a wartości to liczba wyświetleń.
Natknąłem się na ten wątek http://www.magentocommerce.com/boards/viewthread/27684/? – Ledgemonkey
To zadziałało, ale, jak powiedziano w wątku, było dość powolne. Dzięki za pomoc! – matt