5

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

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
27nov
  • 71
  • 1
  • 5

3 Answers3

5

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');
Peter O'Callaghan
  • 6,181
  • 3
  • 26
  • 27
  • I have tried getData function, but like a dumb I was expecting an array, not a string so my other function could not work. Thank you so much ! – 27nov Jan 09 '12 at 08:50
1
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"); 
SMacFadyen
  • 3,145
  • 2
  • 25
  • 37
Oğuz Çelikdemir
  • 4,990
  • 4
  • 30
  • 56
-2

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

cdeszaq
  • 30,869
  • 25
  • 117
  • 173