Suman KC
Suman KC

Reputation: 3528

Magento attribute dropdown values(Yes/No) prints (numeric values)

I created an Attribute of type dropdown. I assigned two values of "Yes" & "No". While printing those attributes values while comparing products i get the values like "133" / "134" . Is it because of systems predefined value or what it is ? How can i get the same value as i assigned for options "Yes" or "No" get printed as attribute value?

Note : I tried attribute type 'yes/no' , this prints '1' and '' (this will not be clear to visitors/customers).

Upvotes: 0

Views: 943

Answers (2)

Ankur Goyal
Ankur Goyal

Reputation: 108

for Drop down attributes,use following code to get the text.

$_product->getAttributeText($attributeCode);

Upvotes: 0

Marko Krstic
Marko Krstic

Reputation: 1447

you can get values like this:

$attribute_code = 'code_of_your_attribute';
$model = Mage::getModel('customer/customer'); // if you need customer attribute
$model = Mage::getModel('catalog/product'); // if you need product attribute
$attribute = $model->getResource()->getAttribute($attribute_code);
$options = $attribute->getSource()->getAllOptions();

var_dump($options);

if you want only yes/no:

$array = array();

foreach ($options as $option)
{
    if($option['label'] == "")
        continue;

    $array[$option['value']] = $option['label'];
}

var_dump($array);

Upvotes: 0

Related Questions