2017-07-05 22 views
0

product/list.phpのような視聴数をproduct/view.phpのようにmagento 1にすることはできますか?商品リストのページビュー数をmagentoの商品のようにカウントするには?

リストページを何回閲覧したかを確認しますか?

+0

はいできます。 :) – Twinfriends

+0

あなたはどうすればそれを行うことができることを私に教えていただけますか? –

+0

私たちのガイドラインによると:「書籍、ツール、ソフトウェアライブラリ、チュートリアル、その他のオフサイトリソースを推薦するかどうかを尋ねる質問は、オピニオン回答とスパムを引き付ける傾向があるため、スタックオーバーフローに関するトピックではありません。問題を解決するためにこれまでに何が行われているのか」 - いいえ、私は傾けません。あなたが探しているものは、Googleを開いて検索することで見つけることができます。 5分で完了。 – Twinfriends

答えて

0

Mage_Reports_Model_Resource_Product_Collectionモデルで表示回数を取得できます。あなたがカウントを取得するために$product->getViews()を使用できるように

// 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); 

コレクション内の各項目は、ビューのプロパティが設定されたcatalog/productインスタンスです。

あなたが製品全体のモデルをロードし、専用のビュー数を必要としない場合、あなたはこのようにそれを得ることができます。

$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です値はビュー数です。

関連する問題