2012-07-12 45 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

相关问题