I'm trying to get all configurable attributes of a configurable product.

$product_attributes = $_product->getTypeInstance(true)->getConfigurableAttributesAsArray($_product)

So far it worked properly, but suddenly it showed an error message

Call to a member function getId() on a non-object in app/code/core/Mage /Catalog/Model/Product/Type/Configurable.php and I have no idea of what's going on.

I tried to debug and in Configurable.php line 276, $this->getConfigurableAttributes($product) returns 3 attributes but the first one doesn't belong to the product

And line 283, $attribute->getProductAttribute() returns null, therefore, $attribute->getProductAttribute()->getId() caused the problem, crashed the app.

If anyone suffered this issue, please tell me what's going on. Any help will always be appreciated.


I found the problem: https://stackoverflow.com/a/25662721/1974153

It's because I'm running multi websites on Magento, product A belongs to both site 1 and site 2.

In site 1, A has 1 attributes, in site 2 A has 2 other attributes. Then it caused the problem. I will try to get attributes that available in the current site only. Hope it would solve the problem.

| improve this answer | |

I had this error. The problem was that the attributes defined in


was not part of the attribute set defined in


Adding the attribute to the attribute set solved the problem for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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