Contact Email:
jminfotech contact jminfotech gplus jminfotech skype jminfotech phone jminfotech yahoo jminfotech facebook jminfotech twitter

Magento Product Attributes

Posted at : 24-July-2014

Get Custom Attributes Value in Frontend:

1. Suppose our custom attribute code is “test_attr” and of type Text Field or Text Area .

$product = Mage::getModel("catalog/product")->load($product_id);
echo $product->getTestAttr();

 I use getTestAttr() because my attribute code is “test_attr”, Use uppercase after underscore or begining of character, like for “testattr” method should be getTestattr() for “test_attr” method should be getTestAttr()


 2. Suppose our custom attribute code is “test_attr” and of type Multiselect or Dropdown . <?php $product = Mage::getModel("catalog/product")->load($product_id) $attributeCode = 'test_attr'; $AllAttributes = $product->getAttributes(); if(array_key_exists($attributeCode , $AllAttributes)){ $Attribute = $AllAttributes["$attributeCode"]; $Value = $Attribute->getFrontend()->getValue($product); } echo $Value; ?>


3. To get all the options of attributes . <?php $attributeId = Mage::getResourceModel ('eav/entity_attribute')-> getIdByCode ('catalog_product','test_attr'); $attribute = Mage::getModel ('catalog/resource_eav_attribute') ->load($attributeId); $attributeOptions = $attribute->getSource()->getAllOptions(); foreach($attributeOptions as $each){ echo $each["label"]." ".$each["value"]."<br>"; } ?>


4. To get value of text type, attribute. $_product->getData("test_attr");


5. To get values of multiselect type, attribute. $_product-> getResource()-> getAttribute('test_attr')-> getFrontend()-> getValue($_product);


6. To get value of dropdown type, attribute. $_product->getAttributeText('test_attr');


Tags: magento tips , magento tutorial


Leave a Comment:

* Required Fields