The StoreFront Consulting Magento Blog

The official Magento development blog of StoreFront Consulting, Inc.

How to Fix New Magento Google Base Issue

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.

Book Review: PHP In a Nutshell

PHP In a Nutshell

PHP In a Nutshell

I found myself getting into the PHP game rather late and needed a book to go to for the basics. I have been programming in languages derived from C syntax for over a decade and a half now (C/C++, Java, C#), so I figured I could come up to speed with PHP rather quickly. My assumption turned out to be correct and PHP In a Nutshell turned out to be my guide book and go to reference for basic syntax.

 

Last summer I began customizing some eCommerce sites built on the Magento open source eCommerce platform. Magento is implemented in PHP and makes heavy use of the Zend Framework. I purchased Practical Web 2.0 Applications with PHP to learn about the Zend Framework and integrating PHP with spiffy Ajax enabled interfaces. After reading this, tinkering with some code and a bit of googling I found I was able to read and modify your basic PHP code. PHP does borrow most of its syntax from C/C++, so this wasn’t too much of a challenge.

So PHP is not hard to read / write if you are already familiar with HTML and some C-derived language. That said, there are quite a few bits of syntax which are new and unique in PHP. New operators, variable variables, etc. Plus PHP is a dynamic language (see Wikipedia’s entry for Dynamic programming language for more information), so the semantics don’t work quite like C/C++ either. What I needed was a quick reference to all of these little details. Of course I tried the official PHP docs first. These definitively cover the material I was after and the User Contributed Notes are great to get some tips about real world applications or read some in depth posts about fine details about some particular language feature. But I didn’t find the online docs easy to skim quickly and they weren’t clear and concise enough for my needs and my taste.

Essentially I wanted to spend a few hours one afternoon skimming some resource and dump 90% of the PHP language into my brain. The resource I ultimately settled on was PHP In a Nutshell and I was quite pleased with the result. To say this book is clear and concise hits the nail on the head. I was in and out in a few hours and was well on my way to being a PHP expert.

All of this is not to say that the book is perfect, however. I usually have no problem finding fault, even in things I love, and I had no problem doing so here. The chapter devoted to object oriented programming (OOP) in PHP tried to be all things to all people. That is, it tried to introduce OOP from scratch, show the differences between PHP 4 and PHP 5 and also to provide a reference to the object oriented features of PHP. All three of these goals were comprised, and I believe the end result is not of much use for any of the three purposes. Given the overall scope of the book, I believe it would have been best to assume anyone reading the chapter was already familiar with OOP and to provide a reference for these folks. Those seeking to learn OOP in general will be much better served by other books.

Overall rating: 8 out of 10

-Garth Brantley