0

I am trying to write a script that creates configurable products. Ive been using this as a guide: http://inchoo.net/magento/programmatically-create-a-configurable-magento-product/

When I get to this line:

$configurableAttributesData = $configProduct->getTypeInstance()->getConfigurableAttributesAsArray();

The script crashes and kicks out this error:

Fatal error:  Call to a member function getId() on a non-object in /home/buyfrom/public_html/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php on line 283

Following a comment on this page, I changed that line to the following:

$possibleAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

But I am still getting this error. Can anyone suggest how to fix this?

3
  • What version of Magento? Have you re-indexed?
    – Smartie
    Sep 4, 2015 at 12:03
  • version 1.9.2 - reindexed, flushed cache, etc...
    – Jimmery
    Sep 4, 2015 at 12:07
  • There is one (or multiple attributes) that seems to be invalid. Open up that Configurable.php file, and at the top of the getConfigurableAttributesAsArray function, add : if(!is_object($attribute->getProductAttribute())) { var_dump($attribute); continue; } then inspect the output Sep 4, 2015 at 13:29

1 Answer 1

0

I found the solution for this. Your product attribute_set_id is set wrong. It may be set to a attribute_set_id that does not have the attribute you are trying to use included to its attribute set. If you dump your product you may see the attribute_set_id.

The solution is to set the attribute set to one that has the attribute included before calling the function.

So do something like this:

$product->setAttributeSetId(10);
// 10 is the Id of one of your attribute sets that has the attribute included
$product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

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.