magento get product attribute value

If you do not know how to get the simple product , Bundle product, configurable product and Grouped product attribute value in magento than don't worry this magento blog  or magento tutorial will tell you how to get the product Attribute value in magento.
Using this code You can get custom Attribute or default attribute value and label.

Open the template file “view.phml” from path template/catalog/product/

Find below code in the file.
<?php $_product = $this->getProduct(); ?>

Put below code and check on frontend.

<?php 
echo '<pre>';
$attributes = $_product->getAttributes();
foreach ($attributes as $attribute) 
{
    //if ($attribute->getIsVisibleOnFront()) {

        echo "<br/>".$attribute->getName();

       echo "<br/>Apply To = ".$attribute->getData('apply_to'); 
      
      // print_r($attribute->getData()); // get All product attribute value

        echo "<br/>Attribute Value = ".$attribute->getFrontend()->getValue($_product); // get product Attribute value

         echo "<br/>Attribute Label value = ".$_product->getAttributeText($attribute->getAttributeCode()) ; 
         // display value only select checkbox and drop down only         
        
        echo "<br/>";
        
    //}
}
echo '</pre>';
?> 

1 comment: