AWIA LogoFacebookGoogle Plusicon-codingicon-computericon-designicon-drawicon-drupalicon-maintenanceicon-mapicon-wordpressLinked InTwitter

Google Merchant is used a lot by SEO companies to help their clients boost their rankings. Commerce Kickstart doesn’t come with a native way of supplying a product feed, but with Views and a couple of modules it can be easily done.
No doubt, there is probably a better way of doing it, but this is what worked for me.

Modules used

Before starting, check to make sure you hav the following modules installed and enabled:

  • Commerce Kickstart 2
  • Views
  • Views Data Export
  • Image URL formatter.

What do we want?

I want to end up with a CSV file of all the current products that is generated dynamically. That CSV file needs to match the requirement for Google Product Feed. You can find information on that at https://support.google.com/merchants/answer/188494?hl=en#US.
Tip: Make sure you have a category set up for Google Product Category. Sometimes the category system you want to set up does not match yours. So, you might want to operate 2 classification systems.

Stage One: Set up the initial view

For starters, we will work on a page display. Page display is a node. Not all the fields you want are available from the node, but we can add the other fields later. Once the view is working on page display, we can add other displays. For Format, I’ve used Table to start with. This is so we can see what’s going on. As a starting point, you should use Fields rather than Node. That way we can manipulate the fields and bend them to our will.
Create a new view. Call it something like “Google Product Data Feed” (or whatever you want to call it.)

Displays

For the time being, just leave it the display as page

Title

I called mine “Data Feed For Google Shop”.

Format

Table

Fields

Our table should have about 4 fields on the display.

  • Content: Title (Title)
  • Content: Body (Description)
  • Content: Product category (Product Type)
  • Content: Path (Link)

Tips:

  • Change the labels to match the Google Merchant criteria. The labels will become the headers for the CSV output later on.
  • Make sure all the fields are formatted as text and turn off any embedded links. You will ultimately end up with a text file without embedded hyperlinks.
  • Use the trim option for body to avoid having long text in the body(description)
  • On the path(link), set it to output the whole URL by ticking “Use absolute link (begins with "http://")” box.

Filter criteria

Content: Published (Yes)
Content: Type (= Product display)

Page Settings

You will need to set a path for your page before you can save. I used “data-feed-for-google-shop” as my URL. This can be whatever you want.

Header

Leave untouched as this is not needed.

Footer

Leave untouched as this is not needed.

Pager

While you are developing your view, I suggest limiting the number of items displayed to something like 10. Once the view is displaying the data you want, then change it to display all,

Advanced

Leave untouched for now. We will be visiting here in the next step.

The Results

You should end up with a table that is similar to below.

Title Description Product Type Link
Hello Kitty Hello Kitty is from England and … Adult Kigus http://kiguzoo.com/shop/hello-kitty
Gloomy Bear -Pink Gloomy Bear is a 2 meter tall … Adult Kigus http://kiguzoo.com/shop/gloomy-bear-pink
Unicorn - Kids Who said unicorns don’t exist??? .. Kids Kigus http://kiguzoo.com/shop/unicorn-kids

 

Stage Two: Getting access to the product entity fields.

In Drupal Commerce, products exist as entities not as nodes. This seems confusing to start with but does allow Drupal Commerce to do some amazingly powerful things.
We have a node type called “Product Display” that displays the basic skeleton of the product to the world. So far all we can see are the fields attached to the product display. None of the other fields such as price, category, image are available to the view yet.
To get the product fields, you need to add the Product entity to the query. To do that click on the Advanced link to open up other options.

  • Under Relationships click Add
  • Search until you find “Products referenced by field_product
  • Apply (all displays)

You should now see:
Relationships
Content: Product
In your Views UI

Stage Three: Add the product entity fields

You should now have access to the product fields. This will allow to add fields like images, price, brand size etc. Most of the fields should be displayed as text except for images.
I recommend setting up the images as below. This will help you see what Google will see. The image will need to be converted to a URL. This is in the next stage.
For the time being when configuring this field, leave image formatted as “image”. (We will deal with image for CSV next). The Settings should be:

  • Relationship: Products referenced by field product
  • Create Label – ticked
  • Label: Image
  • Formatter: Image
  • Image Style: product thumbnail
  • Link image to: Nothing
  • Mutliple field settings:
    • Display all values in the same row (ticked)
    • Display 1 value starting from 0
  • Leave the other settings as default

Once finished, your Views UI under Fields should look something like:

Fields

(Products referenced by field_product) Commerce Product: SKU (Id)
Content: Title (Title)
Content: Body (Description)
(Products referenced by field_product) Commerce Product: Google Merch Category (Google Product Category)
Content: Product category (Product Type)
Content: Path (Link)
(Products referenced by field_product) Commerce Product: Images (Image)
(Products referenced by field_product) Commerce Product: Price (Price)
(Products referenced by field_product) Commerce Product: Brand (Brand)

Tip

  • Looking at the above you will be able to see which fields come from the Product display node and which fields come from the referenced product entity.

Stage Four: Getting the image URL

I wrestled with this one. I tried to rewrite the output of the image to a link. One would think that using the replacement pattern [field_images] would give a link, but no combination I tried could produce a url. I even tried using the rendered node to see if I could extract the URL from it. It wouldn’t work.
There is a module that comes to the rescue. Image URL Formatter (https://drupal.org/project/image_url_formatter) is a simple little module that fixed it for me.
If this module is installed and enabled try configuring the Commerce Product Images field.

  • Formatter: Image URL
  • URL Type: tick full URL
  • Leave all other settings untouched

Once done, your table display should look something like:


Id
Title Description Product Type Link Image

Price

Brand

Size

kigu-hellokitty Hello Kitty Hello Kitty is from England … Adult Kigus http://kiguzoo.com/shop/hello-kitty http://kiguzoo.com/sites/default/files/styles/product_thumbnail/public/2R4W7023.jpg $85.00 AUD Hello Kitty Adult
kigu-gloomybear-pink Gloomy Bear -Pink Gloomy Bear is a 2 meter tall… Adult Kigus http://kiguzoo.com/shop/gloomy-bear-pink http://kiguzoo.com/sites/default/files/styles/product_thumbnail/public/2R4W1955.jpg $85.00 AUD Gloomy Bear Adult

Stage Five: Adding other Google fields

Google requires a field for condition and stock availability. You could add these fields to your product entity but I think this takes up unnecessary space in our database. If you all your stock is new and your views query only gets products that are in stock, then you can safely generate these fields when needed.
In your Views UI under Fields

  • Add
  • Global: Custom text
  • Apply (all displays)
  • Create a label (tick)
  • Label: Condition
    • Text: new

Repeat the same for availability. Once done, your Views UI should look something like this:

Fields

(Products referenced by field_product) Commerce Product: SKU (Id)
Content: Title (Title)
Content: Body (Description)
(Products referenced by field_product) Commerce Product: Google Merch Category (Google Product Category)
Content: Product category (Product Type)
Content: Path (Link)
(Products referenced by field_product) Commerce Product: Images (Image)
(Products referenced by field_product) Commerce Product: Price (Price)
(Products referenced by field_product) Commerce Product: Brand (Brand)
Global: Custom text (Condition)
Global: Custom text (Availability)
(Products referenced by field_product) Commerce Product: Size (Size)

Filter criteria

Content: Published (Yes)
Content: Type (= Product display)
(Products referenced by field_product) Commerce Product: Stock (> 0)
(Products referenced by field_product) Commerce Product: Status (Yes)

Output

The output table should look something like this:


Id
Title Description Google Product Category Product Type Link Image Price Brand Condition Availability Size
kigu-hellokitty Hello Kitty Hello Kitty is from England .. Clothing & Accessories > Clothing > One-Pieces Adult Kigus http://kiguzoo.com/shop/hello-kitty http://kiguzoo.com/sites/default/files/styles/product_thumbnail/public/2R4W7023.jpg $85.00 AUD Hello Kitty new in stock Adult
kigu-gloomybear-pink Gloomy Bear -Pink Gloomy Bear is a 2 meter tall… Clothing & Accessories > Clothing > One-Pieces Adult Kigus http://kiguzoo.com/shop/gloomy-bear-pink http://kiguzoo.com/sites/default/files/styles/product_thumbnail/public/2R4W1955.jpg $85.00 AUD Gloomy Bear new in stock Adult

Stage Six: Exporting As CSV

Now we have a table displaying as we want, it is time to convert it to a format that Google will like.

  • The Views Data Export module (https://drupal.org/project/views_data_export) does all the magic for this. Make sure you have this enabled.
  • In your displays click +Add
  • Select Data Export
  • Display name: CSV Export

Format

CSV File

Data export settings

Path: data_feed_for_google_shop.csv (or whatever name you want)

Output

If all goes well, you should end up with an output similar to below:

"Id","Title","Description","Google Product Category","Product Type","Link","Image","Price","Brand","Condition","Availability","Size" "kigu-hellokitty","Hello Kitty","Hello Kitty is from England …","Clothing & Accessories > Clothing > One-Pieces","Adult Kigus","http://kiguzoo.com/shop/hello-kitty","http://kiguzoo.com/sites/default/files/styles/product_thumbnail/public/2R4W7023.jpg?itok=Uf8DTrF9","$85.00 AUD","Hello Kitty","new","in stock","Adult"

Stage Seven: Tidy up

You are done :) . However, you might want to tidy up a couple of things. Enjoy your Google data feed.

  • You may need set your pager to display all products
  • You might want to restrict your feed to certain user groups

Links

Categories

Posts

All posts