gpcola
gpcola

Reputation: 41

Magento - Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray

I'm getting the following error when I hit a configurable product using the saveRow method from /app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php:

[05-Jul-2011 18:12:32] PHP Fatal error:  Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray() in /home/gp/public_html/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php on line 107

My problem is a little different to others I've come across online perhaps in that I'm calling saveRow() from my own script that is building and maintaining a list of products, downloaded from my supplier by xml feed, in a temporary database before then using magento to add or update them in my site's catalog.

require_once($_SERVER['DOCUMENT_ROOT']."/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php");
$MageProducts = new Mage_Catalog_Model_Convert_Adapter_Productimport();
...
...
foreach($products as $product) {
    $result = $MageProducts->saveRow($product);
}

The first time I hit a configurable product I get this error but if I immediately hit refresh the script runs right past that product and all the way through to the end, passing many simple/configurable product sets on its way, without failing.

Line 107 of ProductImport.php is this line

$cspa  = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);

For some reason the $product->getTypeInstance is returning Mage_Catalog_Model_Product_Type_Simple but only the first time in a session?!

If I add print_r($product->getTypeInstance()) just before that line I get the following for a configurable product

Mage_Catalog_Model_Product_Type_Simple Object ( [_product:protected] => Mage_Catalog_Model_Product Object ( [_cacheTag:protected] => catalog_product [_eventPrefix:protected] => catalog_product [_eventObject:protected] => product [_canAffectOptions:protected] => [_typeInstance:protected] => Mage_Catalog_Model_Product_Type_Simple Object *RECURSION* [_typeInstanceSingleton:protected] => Mage_Catalog_Model_Product_Type_Configurable Object ( [_usedProductAttributeIds:protected] => _cache_instance_used_product_attribute_ids....

Which is clearly wrong...

I want to be able to use my script through cron, but this error is stopping me from doing that so I desperately need some help to fix - can anyone offer some advice?

Upvotes: 4

Views: 9640

Answers (3)

Victor Zubcu
Victor Zubcu

Reputation: 1

That's work just for configurable items, so for this, first check if product is configurable with this code:

if($product->isConfigurable()){
$cspa  = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
....

Upvotes: 0

Manik Thakur
Manik Thakur

Reputation: 294

Before this:

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);

Check $product->isConfigurable();. If it is, only run:

$product->getTypeInstance()->getConfigurableAttributesAsArray($product);

Upvotes: 6

user4007495
user4007495

Reputation: 1

I know this was asked long back but still for anybody who faces this issue in future. I struggled for a week almost and tried different solution found on internet. At last here we go, the issue was i had a simple product with the same sku as the configurable product i was trying to import.

Upvotes: 0

Related Questions