Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vhsu/9984a4e3c7231edf9bf88060ffe01820 to your computer and use it in GitHub Desktop.
Save vhsu/9984a4e3c7231edf9bf88060ffe01820 to your computer and use it in GitHub Desktop.
Shopify Google Product Feed xml generator
{% comment %}
Instructions:
- Create a blank page called 'Google Base Product Feed'and save it
- Open that page for editing and select 'page.google-feed' from the page template selector
- Add a brief site description to the meta-shop-description snippet
- The feed url should now be available at http://www.yoursite.com/pages/google-base-product-feed
- validate your field at http://validator.w3.org/feed/
- when ready, submit your feed at http://base.google.com
Notes:
- If you have to include VAT, either put "(including VAT)" or "(excluding VAT)" in the price field of your products (in Shopify, not the feed) and make the appropriate tax setup in your Google Base Settings
- for more info see http://ecommerce.shopify.com/c/ecommerce-design/t/feedify-your-shop-for-free-using-page-templates-29008
- for a quick tutorial see http://ecommerce.shopify.com/c/ecommerce-design/t/feedify-your-shop-for-free-using-page-templates-29008/#comment-29549
- Google Product feed specifications: https://support.google.com/merchants/answer/188494?hl=en-GB
Credits:
- Michael Larkin: http://www.pixallent.com
- Caroline Schnapp: http://www.11heavens.com
- Jamie: http://www.charlestoncreative.com
Note: with terminal, you can: curl www.yourstore.com/pages/product-feed > product_feed.xml to generate the file.
{% endcomment %}{%- layout none -%}<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>{{shop.name | escape }} Products</title>
<description>Your description</description>
<link>{{shop.url}}</link>
{% paginate collections.all.products by 1000 %}
{% for product in collections.all.products %}
<!-- Item #{{ forloop.index }} -->
<item>
{% if product.metafields.global.title_tag.size > 0 %}
{% assign productTitle = product.metafields.global.title_tag %}
{% else %}
{% assign productTitle = product.title %}
{% endif %}
<title><![CDATA[{{ productTitle | strip_html | strip_newlines | escape | replace: 'amp;', 'and' | replace: '&#38;', 'and' }}]]></title>
<g:brand>Your Brand</g:brand>
<g:product_type>{{product.type | escape }}</g:product_type>
<g:google_product_category><![CDATA[1234]]></g:google_product_category>
<g:id>{{product.id}}</g:id>
<g:condition>New</g:condition>
<description><![CDATA[{% if product.metafields.global.description_tag.localized_value %}{{ product.metafields.global.description_tag.localized_value | strip_html | strip_newlines | replace: 'amp;', 'and' | replace: '&#38;', 'and' | replace: "..", ". " | replace: " ", " " }}{% else %}{{ product.description | strip_html | strip_newlines | replace: 'amp;', 'and' | replace: '&#38;', 'and' | replace: "..", ". " | replace: " ", " " }}{% endif %}]]></description>
<g:image_link>{{product.featured_image | product_img_url: 'large'}}</g:image_link>
{% for image in product.images %}
{% unless image == product.featured_image %}
<g:additional_image_link>{{ image | product_img_url: 'large' }}</g:additional_image_link>
{% endunless %}
{% endfor %}
<link>{{ shop.url }}{{ product.url }}{% assign c=localization.country.currency.iso_code %}{% if c %}?currency={{ c }}{% endif %}</link>
<g:price>{{ product.price | money_without_currency }}</g:price>
<g:quantity>1</g:quantity>
<g:availability>{% if product.available %}in stock{% else %}out of stock{% endif %}</g:availability>
<g:identifier_exists>false</g:identifier_exists>
<g:payment_accepted>Visa</g:payment_accepted>
<g:payment_accepted>MasterCard</g:payment_accepted>
<g:payment_accepted>AmericanExpress</g:payment_accepted>
<g:payment_accepted>Discover</g:payment_accepted>
<g:payment_notes>We also accept Paypal and Google Checkout</g:payment_notes>
</item>
{% endfor %}
{% endpaginate %}
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment