Suman Singh
Suman Singh

Reputation: 1377

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?

Upvotes: 2

Views: 9317

Answers (3)

user7752775
user7752775

Reputation:

Try this,hope it's work for you.

Try this :

$product = Mage::registry('current_product'); then
$product->getName();
$product->getId();

You can try this for product :

$id = $this->getRequest()->getParam('id');
$current_product=Mage::getModel('catalog/product')->load($id);

Upvotes: 1

Keshav Joshi
Keshav Joshi

Reputation: 1

We need to pass store value as well to get product attribute directly from resource model. You can get store id by using this code:- Mage::app()->getStore().

So the final query will be :-

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

Upvotes: 0

Gopal Patel
Gopal Patel

Reputation: 238

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

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

Upvotes: 3

Related Questions