'Yes/No Attribute' in magento - how to get text value

by Marek Badura   Last Updated September 19, 2018 11:09 AM

$attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product", $code);
         $options = $attribute_details->getSource()->getAllOptions(false);
       foreach($options as $option){
          echo '<p class="question"></p>';
          echo '<input type="radio" id="'.$code.$option["value"].'" value="' . $option["value"] .'"  class="styled" name=" '.  $code . ' " />';
          echo '<label for="'.$code.$option["value"].'">';
          echo $option["label"];
          echo '</label>';
         }  

Is there a way to get question front end label ? $option[value] is 1/0 and $option[label] is Yes/No - i need to get the "question text"



Answers 3


you are using wrong method isAttributeText

If you want to access the value of Product Attribute then

 $_product->getData('attribute_code');

End If you want tot Display Label Of that Attribute then

 $_product->getAttributeText('attribute_code')

OR

 $_product->getResource()->getAttribute('attribute_code')->getFrontend()->getValue($_product);

And then you can check using isset() of PHP.

Hope you got Proper Answer.

Keyul Shah
Keyul Shah
February 24, 2014 11:00 AM

If you want values for quoted items then you have to use

 $cartItems = Mage::getSingleton('checkout/session')
      ->getQuote()
      ->getAllItems();
foreach ($cartItems as $item) {
    $disableDiscounts = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getDisableDiscounts();
    echo $disableDiscounts;
}

Where attribute code is disable_discount.

Ashwani Panwar
Ashwani Panwar
March 25, 2015 04:17 AM

Complete solution is

if($_product->getData('attribute_code')) {
    echo 'enable';
} else {
    echo 'disable';
}
Pratik Kamani
Pratik Kamani
September 19, 2018 10:09 AM

Related Questions