27nov
27nov

Reputation: 71

How to get the id number of an attribute value on Magento list product page?

I'm looking for a snippet to display attribute value id of a product on a products list page, I already use this piece of code to display attributes values but I need to get their ID number:

$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getAttributeText('icontags');

Example:

Attribute: Color

Value: red

Value Id: 580

Upvotes: 5

Views: 8884

Answers (3)

Oğuz Çelikdemir
Oğuz Çelikdemir

Reputation: 4980

Mage::getModel('catalog/product')->load($_product->getId())->getAttributeText('color');
// will return selected value

// if you want to get option id
$attribute=Mage::getModel('catalog/product')->getResource()->getAttribute("color"); 

Upvotes: 1

Peter O'Callaghan
Peter O'Callaghan

Reputation: 6186

I'm guessing you are referring to the option_id, which can simply be got with getData

$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getData('icontags');

Upvotes: 5

cdeszaq
cdeszaq

Reputation: 31280

$_product->getId() will get you the product id.

Upvotes: -2

Related Questions