2012-07-12 60 views
0

我試圖訪問使用下面的代碼最後一次查看的項目列表:如何獲取Magento上次查看產品的列表?

$attributes = Mage::getSingleton('catalog/config')->getProductAttributes(); 
$model = Mage::getModel('reports/product_index_viewed'); 
// 
$_collection = $model->getCollection()->addAttributeToSelect($attributes) 
        ->excludeProductIds($model->getExcludeProductIds()) 
        ->addUrlRewrite() 
        ->setPageSize($columnCount) 
        ->setCurPage(1); 
// 
$_collection->addPriceData(); 
$_collection->addIndexFilter(); 
$_collection->setAddedAtOrder(); 
// 
Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($_collection); 

我複製這從Mage_Reports_Block_Product_Abstract但是這給產品的創建順序。

回答

0

我懷疑Prasanth會回來這個,但我也一直試圖得到沒有using a block,可能並不總是可用的產品的簡單列表。最後我終於找到你需要這個:

$viewedCollection = Mage::getModel('reports/product_index_viewed') 
        ->getCollection() 
        ->addIndexFilter(); 

祕訣在於addIndexFilter(),它採用了目前客戶或 - 如果不是實際價格 - 當前遊客來代替。從這裏你可以像任何其他收集一樣循環或提取單個陣列:

$viewedProductIds = $viewedCollection->getColumnValues('product_id'); 
+0

10我意識到我沒有說清楚。關鍵是從原來的'setAddedAtOrder()'和其他你不需要的東西。 – clockworkgeek 2012-12-09 17:45:57

相關問題