Drupal Commerce Data Feed for Google Merchant Center

I recently setup a products feed from Drupal 7 to Google Merchant Center, and it took quite a bit of work. I am expecting it to be worth the effort. Maybe it will not be right now, but in the future. I decided to go with xml because it was the simplest to me, and I am not a spreadsheet guy.

Google has great documentation for their product imports here. I went through each row to see exactly what was expected and required. I used Drupal Views, along with three additional module, including Views Data Export, Image Url Formatter, and Views Php. You may not need views php depending on how well your data matches the data google is expecting.

So I created my products view. I decided to make this feed only for Boots and Shoes that were not of the taxonomy "Women's" or "Children". This is because google requires a target audience field for age and gender. Now, I could have easily created a php field that took the taxonomy, and spat out age and gender based on that. Instead I was more focused on getting the required info exported, and imported correctly. Not to mention, this was already a huge feed because of sizes and colors.

I setup my view of product displays, and added a relationship with to my commerce products, and my taxonomy "manufacturerer". I created a "Data Export" display and used XML. You need your XML file to match up with what google expects. I used RSS 2.0 specification which you can view here. So in the XML settings, I used "channe" as root node and "item" as Item node. I also had to edit the XML tpl.php header and footer files in Views Data Export module. I added "<rss version="2.0" xmlns:g="http:// base.google.com/ns/1.0">" to the header and "</rss>" to the footer.

I had to get my data to match what google expected, and this involved adding some custom text fields, some php fields, and getting all the field titles correct (for XML most of the product attributes start with a g: as in g:image, etc). I had to used Batched Export because of my file size. Then I downloaded my file, and uploaded to Google Merchant Center. It is important to already have your website claimed and verified, your shipping and tax settings properly configured (unless each of your products has that info). You can choose to do a test or a regular import. Both will tell you what errors you have in your data. I had some illegal characters in some of my descriptions, a few identical products, and some warnings. From there you can go back to your view, and fix your data.

I was hoping it would not take too much time to then set up a feed that gets updated automatically, but because of my file size it ended up being difficult. I was able to programmatically save my view as a file using #39 here. I put that code into a rules component, and was able to schedule it to run whenver cron maintenance tasks are performed. It worked great if I shortened my list of products, but it timed out when using the full list. I did not think it was worth persuing any further at that point until I see how well google merchant performs. Assuming I could have gotten that working right with large files, I would have then gone to "data import" in google merchant center, and use a feed. Point it to that URL and it should work. I feel like this was worth the effort, and I expect some good results from this.

 

About the Author:

Tommy Sliker

Web Developer

Tommy Sliker, aka Mirakolous, is a creative mastermind, Drupal Front End guru, and a contributor to Drupal Core. He has been producing his own music since he was twelve years old, and has a wide breadth of creative skills including photography, video production, and graphic design.

In addition to his Web work, Tommy's passions include music production, drums, guitar, photography,