Merchant Center XML View Setup
1) Setup new view "content" of type "product"
2) Uncheck "create a page"
3) Set to "Unformatted list" of "fields"
4) Items to display "0" (For all items)
5) Save & Edit
Merchant Center XML Feed Configuration
View Type:: Add "Data Export"
View Title: Add whatever title makes sense to you (Google Shopping)
Format: XML file
Settings: The settings we'll have to come back to ad check boxes to "Disable encoding of XML entities for these fields" once fields are added, however two major settings can be changed up front.
Inside the Format area
Root Node: channel
Item Node: item
Most of the view fields sit within a gray area... You can easily use the existing fields for your site, or you can do what I did and create fields for the product that are specific to Google Shopping.
The following is a list of fields I added to the view. Make sure to change the label to the google xml identifier as denoted from the Merchant Center Help Docs
After each field, I'll denote whether it's a Core View Field, a Core UC Field, a Custom View Field, or a Custom Content Type Field. Keep in mind the "Custom Content Type" can be substituted for your own needs, For example, the description you could easily just use the body of your page or summary of the body. The Title, you could use the title of the page. I created my own separate fields specifically targeting the info I present to Google Shopping. Other fields like "Availability" or "Condition" can either be done as a custom field on the product or you can override ALL of them with a custom view field. It's really up to you. (For example, I used a view field for condition and overrode the results because all I sell is "new" items so there's no reason for me to have a list field on the product page.)
Items marked in red are required by Google to make the feed pass inspection (might be subject to change without notice). google_product_category is required for certain categories... take a look at the Google Merchant docs on google_product_category for details.
Items marked in blue have a unique requirement, where two of the three must be present to pass.
Required Google IDs
Requires Two of Three
Examples of Fields and ID Labels
Add the fields that you want to use, and replace the "Label" with the Google Merchant identifier. For example, Content: Nid would need the label changed to g:id
If you used paragraphs, don't forget to create a relationship to the paragraph reference field on the product.
Content: Nid (g:id) | Core View Field
Content: Shopping Title (title) | Custom Content Type Field
Content: Path (link) | Core View Field
Content: Shopping Description (g:description) | Custom Content Type Field
Content: Image (g:image_link) | Core UC Field
Content: Availability Options (g:availability) | Custom Content Type Field
Product: Sell price (g:price) | Core UC Field
Global: Custom text (g:google_product_category) | Custom View Field
Global: Custom text (g:condition) | Custom View Field (this could easily be a custom content type field)
Content: Product UPC (g:gtin) | Custom Content Type Field
Content: Product MPN (g:mpn) | Custom Content Type Field
Content: Product Brand (g:brand) | Custom Content Type Field
Content: Product Type (g:product_type) | Custom Content Type Field
Content: MPN Available (g:identifier_exists) | Custom Content Type Field
Content: Shipping Banner (g:shipping_label) | Custom Content Type Field
Product: Weight (g:shipping_weight) | Core UC Field
View Field Notes
Content: Path (link)
Edit and check "Use absolute link" under the rewrite results section. This will make sure your domain name is added to the link
Edit and change "Formatter" to "Image URL" and URL Type is "Full URL". This formatter removes all html code from the output and simply displays the URL
Product: Sell price
Change the formatter to Numeric and set the thousands separator to none
Global: Custom text (g:google_product_category)
Originally, I simply set a single category for my store setup. If you need more categories, you might have to get a bit more creative. google docs. Later, I came back and created a new taxonomy vocab with the list of categories that made sense for my business. I created a text field on the vocab that allowed me to enter the category number with the name, then exposed the terms custom number field to the view.
Content: MPN Available
This was simply a Boolean field with a Yes or No. It tells Google whether an identifier is available or not. Learn about it here
Global: Custom text (g:condition)
If you use a custom field with the three options new, refurbished or used, use that instead. Otherwise if all of your products are "new", you can simply set the text to "new" and forget about it.
Add the filters that make sense for your situation. I recommend adding filters that will keep the product from showing if a field is empty. Otherwise you run the chance of Google Shopping kicking back a bunch of errors and disapproving products.
- If you used paragraphs to house the Merchant fields, then you can setup a filter to check for whether or not the paragraph was even created.
- I created a custom field called "Enable on Shopping" as a boolean value, that way I could "disable" the info from getting into the feed without having to remove the entire paragraph.
Data Export Settings
Path: call the file whatever suits your needs. (ex. google-shopping.xml)
View Template File
We need to override two (2) template files to make Google Shopping work. One for the header and one for the footer. Comment out on: https://www.drupal.org/node/2764979 so we wouldn't have to do this.
Create two theme template files in your themes "templates" folder called:
These file names assume you only need 1 xml file for your site... Otherwise you will need to use the more specific template file names.
(You might have to double check your theme name within the views "theme information" area, but if you haven't re-named anything, it should work.)
Edit Theme Header Template File
We need to add some RSS version info stuff to the header of the view that looks like
rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"
Add the rss version part right above the $root_node section like the following:
* @file views-view-table.tpl.php
* Template to display a view as a table.
* - $title : The title of this group of rows. May be empty.
* - $rows: An array of row items. Each row is an array of content
* keyed by field ID.
* - $header: an array of headers(labels) for fields.
* - $themed_rows: a array of rows with themed fields.
* @ingroup views_templates
// Short tags act bad below in the html so we print it here.
print '<?xml version="1.0" encoding="UTF-8" ?>';
<?php print "\n" ?>
<<?php print 'rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"' ?>>
<<?php print $root_node; ?>>
Edit Theme Footer Tempalte File
Next, we need to close the RSS in the footer template file views-data-export-xml-footer.tpl.php.
Copy and paste the following into the theme file.
</<?php print $root_node; ?>>
At this point, you can save the view and review the data. The views preview only outputs 25 or so results, so to make sure all of your products are in the feed, you'll have to check the actual feed.
If you have HTML code showing up in the feed, this is where you'll have to go back to the View Format -> Settings and add a checkbox to the various fields under the Disable encoding of XML entities for these fields area.