Search code examples
magentoproductcatalog

How to get product name in magento?


I am trying to get only product name using the product id.

I have tried the below:

$product = Mage::getModel('catalog/product')->load(PRODUCT_ID);
$product->getName();

It load the whole resource object and than we can get the name using $product->getName() but I need only single name so we can reduce the extra overheads.

$product = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name')->addAttributeToFilter('entity_id', PRODUCT_ID)->load();

It also load the resource object.

is there any easiest way to get the product name( for exa. 'Test product') without loading the resource object?


Solution

  • Use getAttributeRawValue() With this you can get the attribute value of your product :

    $attribute_value = Mage::getResourceModel('catalog/product')->getAttributeRawValue(PRODUCT_ID, 'attribute_code');