Magento – How to check if attribute exist in product attribute set? Magento

attributescatalogmagentoproduct

How to check if attribute exist in product attribute set?

I need to know if a product has an attribute for its set of attributes.

I get the attribute with:

$attrPricekg = Mage::getModel('catalog/product')->load($_product->getId())->getPricekg();

If attribut exist in product attribute set, $attrPricekg display: set value for the product
or 0 if no value set for the product.

If the attribute does not exist in product attribute set, $attrPricekg display 0. This is my problem.. I need to avoid this, I want to check that the attribute does not exist for that product.

Thanks.

Best Answer

now I'll provide an answer which works regardless!

$product = Mage::getModel('catalog/product')->load(16);

$eavConfig = Mage::getModel('eav/config');
/* @var $eavConfig Mage_Eav_Model_Config */

$attributes = $eavConfig->getEntityAttributeCodes(
    Mage_Catalog_Model_Product::ENTITY,
    $product
);

if (in_array('pricekg',$attributes)) {
    // your logic
}
Related Topic