Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richpeck/e7d32d1c140ab612fb1997a2752967f4 to your computer and use it in GitHub Desktop.
Save richpeck/e7d32d1c140ab612fb1997a2752967f4 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
https://gist.github.com/cameroncowden/d1877c74acb352390720770406c266d6
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>{{ page.content | strip_html }}</description>
<link>{{shop.url}}</link>
{% paginate collections.all.products by 1000 %}
{% for product in collections.all.products %}
<!-- Item #{{ forloop.index }} -->
<item>
<title><![CDATA[{{ product.title | strip_html | strip_newlines | escape | replace: 'amp;', 'and' | replace: '&#38;', 'and' | replace: "é", "e" | replace: "à ", "a", | replace: '&#39;', "'" }}]]></title>
<g:brand>{{product.vendor | escape }}</g:brand>
<g:product_type>{{product.type | escape }}</g:product_type>
<g:id>{{product.id}}</g:id>
<g:condition>New</g:condition>
<description><![CDATA[{{ product.description | strip_html | strip_newlines | replace: 'amp;', 'and' | replace: '&#38;', 'and' | replace: "..", ". " | replace: " ", " " | replace: "‘", "&#39;" | replace: "’", "&#39;" | replace: "&#8216;", "&#39;" | replace: "&#8217;", "&#39;" | replace: "&#8217;", "&#39;" | replace: "’", "&#39;" | replace: "“", "&#39;" | replace: "‘", "&#39;" | replace: "´", "&#39;" | replace: "“", "&#34;" | replace: "”", "&#34;" | replace: "&#8211;", "-" | replace: "–", "-" | replace: "—", "-" | replace: "–", "&mdash;" | replace: "—", "&mdash;" | replace: "%", "&#37;" | replace: "©", "&copy;" | replace: "®", "&reg;" | replace: "â„¢", "&trade;" | replace: "£", "&pound;" | replace: "ï¿­", "&#42;" | replace: "•", "&#42;" | replace: "”", "&#39;" | replace: "&#233;", "e" | replace: "é", "e" | replace: "à ", "a" | replace: "ó", "o" | replace: "ê", "e" | replace: "Ø", "O" | replace: "&#8482;", "" | replace: "&#174;", "" }}]]></description>
<g:image_link>{{product.featured_image | product_img_url: 'master' | replace: "//", "https://" }}</g:image_link>
{%- if product.images.size > 1 %}
{% for image in product.images %}{%- if forloop.first or forloop.index > 4 -%}{%- continue -%}{%- endif -%}<g:additional_image_link>{{ image | product_img_url: 'master' | replace: "//", "https://" }}</g:additional_image_link>
{% endfor %}{%- endif -%}<link>{{shop.url}}{{product.url}}</link>
<g:availability>{%- if product.available -%}in stock{%- else -%}out of stock{%- endif -%}</g:availability>
<g:price>{% if product.compare_at_price and product.price < product.compare_at_price %}{{ product.compare_at_price | money_with_currency | remove: "€" | remove: "$" | replace: ",", "." }}{% else %}{{ product.price | money_with_currency | remove: "€" | remove: "$" | replace: ",", "." }}{% endif %}</g:price>
{% if product.compare_at_price != product.price and product.price < product.compare_at_price %}<g:sale_price>{{product.price | money_with_currency | remove: "€" | remove: "$" | replace: ",", "." }}</g:sale_price>{% endif %}
<g:quantity>1</g:quantity>
<g:shipping>
<g:price>{{ '0.0' | money_with_currency | remove: "€" | remove: "$" | replace: ",", "." }}</g:price>
</g:shipping>
{% if product.options.size > 0 %}{%- for option in product.options_with_values -%}{%- if option.name == 'Taglia' or option.name == 'Size' -%}{%- assign option_index = 'option' | append: forloop.index -%}<g:size>{{- product.selected_or_first_available_variant[option_index] -}}</g:size>{%- endif -%}{%- endfor -%}{% endif %}
<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