StoreFront Consulting

Blog

StoreFront Consulting provides eCommerce solutions to small and mid-size businesses

How to Fix New Magento Google Base Issue

  • Garth Brantley
  • 05.14.2010
  • Magento Bug Fixes

Google Merchant Center
Due to some changes in the public Google Base / Google Merchant Center attributes feeds, an issue with Magento’s Google Base functionality has popped up. As far as I can tell, this issue will affect all versions of Magento. I have personally verified that the issue affects 1.4.0.1 and 1.3.2.4 and made the fix for several clients. I have put together this post with detailed instructions about fixing the error in the hopes that it will save some others time in dealing with the issue.

If you are receiving the following error message, then this fix is for you. The error occurs when trying to edit Google Base attributes in the Magento backend. It can be duplicated by navigating to the Catalog > Google Base > Manage Attributes screen in the Magento backend and clicking the Add Attribute Mapping button.

Notice: Undefined offset: 1 in app/code/core/Mage/GoogleBase/Model/Service/Feed.php on line 120

 

How to Fix Magneto Google Base Error (Short Version)

  1. Connect to your server via FTP, SFTP, SSH, your web control panel or some means which will allow you to replace PHP code files.
  2. Navigate to your Magento base folder. This is typically something like ‘/var/www/magento’ or ‘/home/mageuser/public_html/magento’.
  3. Find the correct Google Base core module code file. You will looking for ‘app/code/core/Mage/GoogleBase/Model/Service/Feed.php’.
  4. Replace the Feed.php file with this download. We are making this download available to make it possible for non-technical users to patch their Magento systems. Presumably this patch or equivalent will be included in the next releases of Magento. Download the patched Feed.php file from here, enclosed in a .zip file.
  5. Logout and login to the Magento Admin GUI and navigate to the Catalog > Google Base > Manage Attributes screen in the Magento backend and click the Add Attribute Mapping button to verify that the fix has worked.

 

How to Fix Magneto Google Base Error (Full Details)

  1. Connect to your server via FTP, SFTP, SSH, your web control panel or some means which will allow you to edit PHP code files.
  2. Navigate to your Magento base folder. This is typically something like ‘/var/www/magento’ or ‘/home/mageuser/public_html/magento’.
  3. Find the correct Google Base core module code file. You will looking for ‘app/code/core/Mage/GoogleBase/Model/Service/Feed.php’. Open this file with a text editor. You can download the file locally, edit it and re-upload to the server or you can use an editor which runs directly on the server through SSH or your web control panel.
  4. Find lines 120 to 132 in the original version of Feed.php. They should look like this:
    1. $item->setLocation($entry->id->text);
    2. $itemTypes[$type] = $item;
    3. $typeAttributes = $entry->extensionElements[1]->extensionElements;
    4. $attributes = array();
    5. if (is_array($typeAttributes)) {
    6.     foreach($typeAttributes as $attr) {
    7.         $name = $attr->extensionAttributes['name']['value'];
    8.         $type = $attr->extensionAttributes['type']['value'];
    9.         $attribute = new Varien_Object();
    10.         $attribute->setId($name);
    11.         $attribute->setName($name);
    12.         $attribute->setType($type);
    13.         $attributes[$name] = $attribute;
    14.     }
    15. }
    16. ksort($attributes);
    17. $item->setAttributes($attributes);
  5. Replace the old lines 120 to 132 in Feed.php with the lines 120 to 138 from the below code example. The result should look like this:
    1. $item->setLocation($entry->id->text);
    2. $itemTypes[$type] = $item;
    3. // GOOGLE BASE FIX
    4. $attributes = array();
    5. // Error: Notice: Undefined offset: 1 in ...
    6. // Add extra test to make sure this
    7. // extensionElements array element exists
    8. if(count($entry->extensionElements) >= 2) {
    9.     $typeAttributes = $entry->extensionElements[1]->extensionElements;
    10.     if (is_array($typeAttributes)) {
    11.         foreach($typeAttributes as $attr) {
    12.             $name = $attr->extensionAttributes['name']['value'];
    13.             $type = $attr->extensionAttributes['type']['value'];
    14.             $attribute = new Varien_Object();
    15.             $attribute->setId($name);
    16.             $attribute->setName($name);
    17.             $attribute->setType($type);
    18.             $attributes[$name] = $attribute;
    19.         }
    20.     }
    21. }
    22. // END GOOGLE BASE FIX
    23. ksort($attributes);
    24. $item->setAttributes($attributes);
  6. Save the resulting Feed.php file.
  7. Logout and login to the Magento Admin GUI and navigate to the Catalog > Google Base > Manage Attributes screen in the Magento backend and click the Add Attribute Mapping button to verify that the fix has worked.

Ready to Start? Let's Chat