CODE

Google Shop XML Feed

Dynamically create a Google Shop feed in XML format for your eCommerce products.

v1.0.0

This uses the ability to parse Liquid in TXT based files, that was released in v7.0.3, to construct the XML format required for Google Shop feed submission.

NOTE:
This method requires your site to be running on version 7+

  1. Via the File Manager, or your code editor of choice and FTP, create a file anywhere in your site's file system with the file extension of .xml and copy/paste the below code into the file body.

    Be sure to update any manual, hard-coded details, such as title and description (highlighted below in bold).

    When accessing the created XML file in the browser, using the liquid=1 URL parameter, you should see the populated products from your site create the XML items in the feed.
    For example, if your sit edomain is mydomain.com and you XML file was created in a folder called 'assets' with a file name of 'shop-feed.xml', your feed URL would look like this: https://mydomain.com/assets/shop-feed.xml?liquid=1.

    {% comment %}<!-- Treehouse CODE v1.0.0 -->{% endcomment %}
    {% component source: "Products", layout: "", limit: "1000", collectionVariable: "prodfeed", type: "module" %}
    {% component type: "domain_settings", collectionVariable: "urldata" %}
    <?xml version="1.0"?>
    <rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
        <channel>
            <title>Max Template</title>
            <link>https://{{urldata.domain}}/shop</link>
            <description>Browse our wide range of products...</description>
            {% for p in prodfeed.items %}
            <item>
                <g:id>{{p.id}}</g:id>
                <g:title>{{p.name}}</g:title>
                <g:description>{% if p.metaDescription != '' %}{{p.metaDescription | replace: ' & ', ' and ' | strip_html}}{% else %}{{p.specifications | replace: ' & ', ' and ' | strip_html}}{% endif %}</g:description>
                <g:link>https://{{urldata.domain}}{{p.url}}</g:link>
                <g:image_link>https://{{urldata.domain}}{% if p.largeImage != '' %}{{p.largeImage}}{% else %}{{p.smallImage}}{% endif %}</g:image_link>
                <g:condition>new</g:condition>
                <g:availability>{% if p.EnableInventoryControl == true %}{% if p.InStock > 0 %}in stock{% else %}out of stock{% endif %}{% else %}in stock{% endif %}</g:availability>
                <g:price>{% if p.RecommendedPriceWithTax != '' %}{{p.RecommendedPriceWithTax}}{% unless p.RecommendedPriceWithTax contains '.' %}.00{% endunless %}{% else %}{{p.priceWithtax}}{% unless p.priceWithTax contains '.' %}.00{% endunless %}{% endif %} {{urldata.FormatSetting.Currency.Code | prepend: ' '}}</g:price>
                {% if p.OnSale == true %}<g:sale_price>{{p.priceWithTax}}{% unless p.priceWithTax contains '.' %}.00{% endunless %} {{urldata.FormatSetting.Currency.Code | prepend: ' '}}</g:sale_price>{% endif %}
                {% comment %}<g:gtin>{{p.SKUCode}}</g:gtin>{% endcomment %}
                <g:brand>Max Template</g:brand>
            </item>
            {% endfor %}
        </channel>
    </rss>

    NOTE:
    You may notice that the gtin property is commented out. It has been set up to use the SKUCode value, as Google's documentation indicates this property is required. However, unless you're products are using actual GTIN numbers this may cause validation issues with Google.
    My testing has found that this property doesn't seem to be required - therefore it's currently commented out. Feel free to experimaent with this as need.

    Additionally, this XML feed seems to also work for the Facebook/Meta Ads Catalogue feed. BONUS!

Comments or questions? Head over to the Treepl CMS forum to discuss with the community.