We use cookies on this site to remember: your settings, your history, whether you are logged in and to give you a better experience.
More info about cookies
Accept Cookies
Opt Out
You have an excellent choice of browser. Why not add our quick launch app so you can easily manage your shop in the future.Get our free app from the Google Chrome Store.
Login       Register

Extending the Google Shopping Content Model.

Extending the Google Shopping Content Model.

Warning, this article may include technical content, jargon, waffle and fluff.

This article is intended to help other developers that are working with the Google Shopping (or Google Merchant) API.

Once again, if you're a shop owner using us we have already done all this for you, we have only put this article up to try and help others and share our knowledge.

This article will explain how to extend the model to read "warnings". These are returned by Google and generally contain useful suggestions on how to improve a product description to ensure it is found by buyers searching.

To ensure products on GroovyCart get both a high ranking and appear on Google Shopping, we have a direct feed to Google. This product feed program runs at regularly times during the day and uploads new and changed products to Google using the Google Shopping Content API.

The program is written in Java and is based on the Google sample program (http://code.google.com/.../developers_guide_java.html). The Java program uses a "model" to map API data items to Java variables, thus simplifying the Java application This model is supplied by Google. However, the model is missing some useful items which have been added recently.


This is an example of a warning:

<sc:warnings> <sc:warning> <sc:code>validation/missing_recommended</sc:code> <sc:domain>ProductSearch</sc:domain> <sc:location>brand</sc:location> <sc:message>We recommend including this attribute.</sc:message> </sc:warning> </sc:warnings>

To get Google to return warnings you need to include "warnings" at the end of the URL, e.g. /items/products/schema/batch?warnings

Ok, now let's change the model com.google.api.client.sample.structuredcontent.model

1) As the warnings element is part of the AppControl, we need to edit public class AppControl to include warnings.

@Key("sc:warnings") public Warning warnings;

The @Key is clever, it maps the API XML item "warnings" to the Java data structure "warnings".

2) Next we need to define the data structure warnings in a new file "warning.java".

package com.google.api.client.sample.structuredcontent.model; import com.google.api.client.util.Key; public class Warning{ @Key("sc:warning") public List<WarningDetail> warningdetail; }

3) Finally, to complete the model, create new file "warningdetail.java":

package com.google.api.client.sample.structuredcontent.model; import com.google.api.client.util.Key; public class WarningDetail { @Key("sc:code") public String code; @Key("sc:domain") public String domain; @Key("sc:location") public String location; @Key("sc:message") public String message; /** * Returns a formatted string for displaying the information of the * warning. */ @Override public String toString() { return "Warning: Domain: " + domain + " Code: " + code + " Location: " + location + " Message: " + message; } }

Now let's use the structure in our Java application:

/* Do we have any warnings? */ if (p.appControl.warnings != null) { /* We have warnings. */ haveWarnings = true; /* Google returns a list of warnings - concaternate into a single string. */ if (p.appControl.warnings.warningdetail != null) { for (WarningDetail w : p.appControl.warnings.warningdetail) { /* This will go in the log (full message with all returned fields). */ warningTextLog = warningTextLog + "["+w.code+" "+w.domain+" "+w.location+" "+w.message+"] "; /* This will be displayed to the shop-owner (short friendly message). */ warningText = warningText + w.location+"="+w.message+" "; } } } if (haveWarnings) { /* We have warnings. */ logit(EM,"WARNING, batchID="+p.batchID+" : "+warningTextLog); }

We hope that can help someone!

Be groovy and share us around:
You might be interested in:
You can also find us on: