Magento Get Attribute Code By Id


Magento Get Attribute Code By Id : You can get Attribute code by using attribute id. First load the product by product id and then get the attribute object by product resource. $product->getResource()->getAttribute(‘my_attribute’);. Here we are going to explain this with simple example.


Magento Get Attribute Code By Id

Here is syntax to get the attribute code by id

Magento Get Attribute Code By Id

// use this to get attrId
//$product=Mage::getModel('catalog/product')->load($productId);
//$attr = $product->getResource()->getAttribute('my_attribute');
//$attrId = $attr->getAttributeId(); 
/***get attribute code if you know attribute id.
$attrCode = Mage::getModel('eav/entity_attribute')->load($attrId)->getAttributeCode();

The above example will give the attribute code.


Advertisements

Add Comment

📖 Read More