Recoverable Error: Object of class Mage_Catalog_Model_Resource_Eav_Attribute could not be converted to string
-
07-10-2020 - |
Pregunta
I haven't had any problems but I moved to a new server and really haven't check it out for a while but now when I try to add a product to google shopping I get the following error:
Recoverable Error: Object of class Mage_Catalog_Model_Resource_Eav_Attribute could not be converted to string in /home/xxxxxxx/public_html/app/code/community/BlueVisionTec/GoogleShoppingApi/Model/Attribute/GoogleProductCategory.php on line 30
Here is the code the error is pointing to:
public function convertAttribute($product, $shoppingProduct)
{
// get category from product attribute
-- line 30 here --> Mage::log(__LINE__.$product->getResource()->getAttribute('google_shopping_category'));
$value = $product->getResource()->getAttribute('google_shopping_category')
->getFrontend()->getValue($product);
$value = preg_replace('/\d+ /','',$value);
$shoppingProduct->setGoogleProductCategory($value);
return $shoppingProduct;
}
I've tried many things (mostly guesses) searched on Google and still can't seem to fix this error. Any help would be very much appreciated.
Solución
$product->getResource()->getAttribute('google_shopping_category')
returns an instance of Mage_Catalog_Model_Resource_Eav_Attribute
and when you are doing this __LINE__.$product->getResource()->getAttribute('google_shopping_category')
PHP tries to automatically convert the instance of Mage_Catalog_Model_Resource_Eav_Attribute
to a string and it cannot do that.
An alternative would be to replace that with
$id = $product->getResource()->getAttribute('google_shopping_category')->getId();
Mage::log(__LINE__.$id);
Or, of you need full details of the attribute you can try.
$attributeAsString = print_r($product->getResource()->getAttribute('google_shopping_category'), true);
Mage::log(__LINE__.$attributeAsString);