Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento : getAttributeText doesn't work

Tags:

php

magento

I have a dropdown attribute called "Housing" (attribute code "housing"). I want to get the text of the selected option for a product but the "getAttributeText" function returns nothing.

My code:

$product_object = Mage::getModel('catalog/product')->load($productId);
$housing = $product_object->getHousing();
echo $housing;
echo "<br>";

$housing = $product_object->getAttributeText('housing');
echo $housing;
echo "<br>";

$housing = $product_object->getHousingText();
echo $housing;
echo "<br>";

The function getHousing returns the correct option id but "getAttributeText" and "getHousingText" doesn't return anything.

Any ideas why?

like image 560
Shani1351 Avatar asked Nov 22 '11 10:11

Shani1351


1 Answers

try,

$prod = Mage::getModel('catalog/product')->load($productId);
$housing = $prod->getResource()->getAttribute('housing')->getFrontend()->getValue($prod);
echo $housing;
like image 150
Alan Cole Avatar answered Sep 28 '22 18:09

Alan Cole