3

I need to get attribute_id from eav_attribute table, I have attribute_code and frontend_label, my sql query will be some thing like this.

select attribute_id from eav_attribute where attribute_code = 'sb_store_id'

What will be its equivalent magento statement.

0

2 Answers 2

4

you can get id from attribute code like that

$attribute_code = "sb_store_id"; 
$attribute_details =
Mage::getSingleton("eav/config")->getAttribute('catalog_product',    $attribute_code);

echo $attribute_details->getAttributeId(); //marius suggestion
1
  • 2
    you can just call $attribute_details->getAttributeId() instead of calling getData first.
    – Marius
    Feb 11, 2016 at 9:09
3

Here is how you should do it.

You need to know the entity type to be able to get it (product,category...).

Example for product:

$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY , 'sb_store_id');

Not the answer you're looking for? Browse other questions tagged or ask your own question.