$_viewed_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addViewsCount()
->setOrder('views_count', 'desc')
$_viewed_productCollection->load();
在我启用扁平产品之前,这个方法可以正常工作,然后它就不能再检索产品名称或价格了。但它仍然可以得到的网址,sku等,这真的让我困惑。我打印出了可以返回的数组,那里似乎根本没有名字数据,只有以下内容:
Array (
[views] => 29
[entity_id] => 18
[entity_type_id] => 10
[attribute_set_id] => 38
[type_id] => simple
[sku] => sw810i
[created_at] => 2007-08-23 15:47:44
[updated_at] => 2008-08-08 14:50:56
[has_options] => 0
[required_options] => 0
[is_salable] => 1
[stock_item] => Varien_Object Object
( [_data:protected] => Array
( [is_in_stock] => 1 )
[_origData:protected] =>
[_idFieldName:protected] =>
[_isDeleted:protected] => )
[gift_message_available] => 2
)
是否有任何方法可以使用SKU获得产品名称?可能是这样的:
<?php $sku = $_product->getData('sku'); echo $this->htmlEscape($_product->getName($sku)) ?>