Magento 1.9 – Fix ERR (3): Notice: Array to String Conversion Error

ce-1.9.0.1errormagento-1.9system.log

I spent all of yesterday trying to get to the bottom of this error that appears every time you access a product page on our Magento store (CE edition 1.9.0.1):

2015-07-24T12:20:09+00:00 ERR (3): Notice: Array to string conversion in /[Path to Magento]/app/code/core/Mage/Catalog/Block/Product/View/Attributes.php on line 66

It's this block of code in the attributes.php file:

if (!$product->hasData($attribute->getAttributeCode())) {
    $value = Mage::helper('catalog')->__('N/A');
} elseif ((string)$value == '') {
    $value = Mage::helper('catalog')->__('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
    $value = Mage::app()->getStore()->convertPrice($value, true);
}

specifically this:

} elseif ((string)$value == '') {
  • I've googled the issue and can't find it anywhere else.
  • I assumed it's something to do with product attributes so I deleted
    all of the custom product attributes we'd created one by one.
  • I disabled all extensions one by one.
  • I reverted the design templates back to the default Magento ones.

And still the error kept popping up…

I'm pretty much a novice when it comes to all of this stuff, so my trial and error fixes haven't helped me out… Has anyone got any ideas or can point me in the direction of how to troubleshoot this error a little more?

Best Answer

Pretty simple: You're trying to cast $value as a string for the comparison, but $value is an array. If $value has some kind of value you need in it (perhaps it's nested inside an array) for the comparison, then you must process it so that it is not array.

Do this before the if statement.

var_dump($value); die;

Or

Mage::log($value); // Check var/log/system.log with logging enabled

And just examine how the data is structured in $value. Make it into a string variable.