How to export Products For Google Base

From Shopify Wiki

Jump to: navigation, search

Contents

What is Google Base?

Google Base is a place where you can easily submit all types of online and offline content, which Google makes searchable on their search engine (if your content isn't online yet, we'll put it there). You can describe any item you post with attributes, which will help people find it when they do related searches. In fact, based on your items' relevance, users may find them in their results for searches on Google Product Search and even on Google's main search portal.


Disclaimer

Please use at your own risk. Back up your theme before attempting any of these modifications.

Feed setup

First we need to create a new page through the shopify admin. You can call it whatever you want. I named it "Product Feed".(without the quotes) It doesn't matter what you add to this page, we won't be using it.

Next we add a collection called "Product Feed"(again, without the quotes). Put the products that you want to show up in the feed into this collection either using smart or standard collections.

Now you want to wrap your current theme.liquid content with an if statement.

{% if page.title != 'product-feed' %}
<!DOCTYPE...>
<html>
<head></head>
 <body>
  content
 </body>
</html>
{% else %}<?xml version="1.0" encoding="UTF-8" ?>

<rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0">

<channel>
	<title>{{shop.name}}'s Products</title>
	<description>Description of Your Feed</description>*
	<link>{{shop.url}}</link>
{% for product in collections.product-feed.products %}   
 <item>
   <title>{{product.title}}</title>
   <g:brand>{{product.vendor}}</g:brand>
   <g:condition>New</g:condition>
   <description>{{product.description | strip_html | truncatewords: 50}}</description>
   <g:expiration_date>2007-01-12</g:expiration_date>*
   <guid>{{product.id}}</guid>
   <g:image_link>{{shop.url}}{{product.featured_image | product_img_url: 'Large'}}</g:image_link>
   <link>{{shop.url}}{{product.url}}</link>
   <g:payment_accepted>Visa</g:payment_accepted>
   <g:payment_accepted>MasterCard</g:payment_accepted>
   <g:payment_accepted>Discover</g:payment_accepted>
   <g:payment_accepted>AmericanExpress</g:payment_accepted>
   <g:payment_notes>We also except Paypal and Google Checkout</g:payment_notes>
   <g:price>{{product.price | money_without_currency}}</g:price>
   <g:price_type>starting</g:price_type>
   <g:quantity>1</g:quantity>
   <g:product_type>Your Product Type</g:product_type>*
   <g:tax_percent>6.5</g:tax_percent>*
   <g:tax_region>Illinois</g:tax_region>*
 </item>
{% endfor %}
</channel>
</rss>
{% endif %}

Important:

Make sure that the <?xml version="1.0" encoding="UTF-8" ?> tag is right next to the {% else %} statement. If its not, then this will create a blank line at the top of the page and the xml file won't be compliant. You also want go through and add or remove any attributes you want or don't need. The ones marked with an asterisk need to be modified to your settings. The expiration attribute tells google base how long the listings should be good for. Don't forget to remove the asterisks

For a list of available attributes visit http://google.com/base/products.html


You should now be able to see your feed by navigating your browser to the page name your created. In this example that would be http://www.yourshopname/pages/product-feed. You can also have your customers subscribe to this feed with an RSS reader and now they will then be notified when you add new products. Sweet!

Advanced: Ruby script

Now we need to take the xml data that was generated and save it to an xml file. I created a ruby script which will grab the xml data and pipe it to a file. If you have ruby on your computer you can paste the code below into a text editor and save it with the .rb extension.

require 'net/http'
require 'uri'

url = ARGV[0]
date = ARGV[1]
feed = Net::HTTP.get URI.parse(url)

lines = feed.scan(/<.*>/).flatten
lines.each { |line| puts line.sub(/\d\d\d\d-\d\d-\d\d/, date) }

You can run it like this:

ruby script.rb http://www.myshop.com/pages/product-feed 2007-01-25 >> feed.xml

The first argument is the url of your feed and the second is the g:expiration_date variable

If you don't have ruby, then right click on the page from your browser and select show source. Copy and paste it into a text editor and save it with an .xml extension.

Finally log into your Google Base account and upload it as a bulk upload file.

Here is a link to Google Base if you don't know what its about. http://base.google.com/base/help/about.html?hl=en_US

Enjoy!

Personal tools