0

can someone please tell me how to check if an attribute has been created?

I have a block which displays products based on a given attribute. The thing is if the attribute has not been created, I'm getting an error on the frontend.

Is there a way to check if the attribute exists?

Thanks.

Kusum
  • 3
  • 1
  • 2

3 Answers3

3

Hopefully you can get lots of info about attributes and attributes set in the following article:
http://www.blog.magepsycho.com/playing-with-attribute-set-in-magento/

Thanks

MagePsycho
  • 1,944
  • 2
  • 29
  • 60
2
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'attribute_id');

Try above code which means check the status that is specified attribute available in magento ( if you know the id ).

Oğuz Çelikdemir
  • 4,990
  • 4
  • 30
  • 56
0

Try this as well :

$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
    if ($attribute->getIsVisibleOnFront()) {
        $value = $attribute->getFrontend()->getValue($product);
        // do something with $value here
    }
}
Oğuz Çelikdemir
  • 4,990
  • 4
  • 30
  • 56
  • This is a copy-paste of my own, recent answer: [get an array of all a products attributes in magento](http://stackoverflow.com/questions/4961117/get-an-array-of-all-a-products-attributes-in-magento/4969074#4969074) - And it doesn't even fit the question! – clockworkgeek Feb 13 '11 at 19:57
  • 1
    Yes, you are absolutely right but I didn't steal anything, just share someone. If I am not mistaken, knowledge is universal, isn't it? – Oğuz Çelikdemir Feb 14 '11 at 11:48