Hi All
I currently show a collection of the "Most Viewed" products as a list in my footer. I get the collection using the following code:
$_viewed_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addViewsCount()
->setOrder('views_count', 'desc')
$_viewed_productCollection->load();
This works fine until I enable flat products, and then it can no longer retrieve the product names or prices. It can however still get the url, the sku etc, which really confuses me. I printed out the array of what can be returned, and it seems there’s no name data there at all, only the following:
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
)
Is there anyway to get a product name using it's SKU? Something like this perhaps:
<?php $sku = $_product->getData('sku'); echo $this->htmlEscape($_product->getName($sku)) ?>