Improve your Magento store’s SEO with Google Rich Snippets – tutorial

All of the most popular search engines prefer Microdata, but we do not want to edit our store template files, so we will transfer the data through JSON+LD (JSON Linked Data), and try not to touch it. If you do not have the time to develop your own extension (or you just don’t feel like it ;)), you will find a ready-to-install module further in the article. What do we want to teach? Structural data is capable of providing the search engine with plenty of important data from various websites: cooking recipes, TV guide, information about an organisation. We are going to focus on the essence of our work, which is the product. Therefore, let’s transfer the following data to the results:

  • Name;
  • SKU;
  • Product picture;
  • Short description;
  • URL;
  • Availability;
  • Price;
  • Currency;
  • Category;
  • Colour;
  • Brand;
  • Model;
  • Number of comments;
  • Comment – author, date of publication, title of the comment

Module structure ATTENTION! We should not implement Rich Snippets in online stores, in which we often change the products’ prices. Search engines do not index our products every day, so the data in the search results may be out of date. Let’s launch the store on our local host, make a backup copy of our database, disable the cache in Magento, and create the framework of the add-on:

At this stage, our add-on should be operational. Let’s look for it on the list of modules in the administration panel: System > Configuration > Advanced > Advanced Configuration form Let’s add some code to create our own position in the Magneto configuration and several options to control our add-on:

<tabs>  section informs Magento that we want to have our own position in the configuration of the store, <groups> helps us to keep order in our form. Next, we add the following options:

  • <enabled>…</enabled> – enable/disable the entire module;
  • <review>…</review> – decides if the comments and opinions should be sent to the board;
  • <manufacturer>…</manufacturer> – many stores use add-ons such as Shop By Brands, which are based on other (personal) product support attributes; this field allows for identifying such attributes, which will protect us from positioning the product brand in multiple places when we are adding the product;
  • <color>…</color> – see above;
  • <model>…</model> – by default, Magento does not support this attribute; however, Google allows us to display the model of the given product, so if you have this attribute in your store, you can indicate it here; if you do not, you can create it at any time.

We should note that the <source_model>  attribute indicates the richsnippets/attributes path. Therefore, it will be necessary to create a new file – a model which will enable loading all of the available attributes:

The $attributeArray variable now contains the board with all attributes such as “text”, “select” and “textarea”, expanded with one option with no value (default). Let’s add our new model with the helper and the block to the configuration file, adding the global section to it:

In order to see modifications in the administrative panel, we have to add our menu to it. Let’s paste the following formula after <global> section then:

All done! Now we can manage our new add-on from the administration panel! Let’s log out and log back in to reload the privileges (or else we will see a 404 instead of the form) and go to: System > Configuration. We should see a new tab under the name Creativestyle. Let’s add a few default settings for our fields and the information on the template file to the end of the file:

2014-05-29_1603     After the changes are saved, we should see the final effect of the backend.   Creating the product data board   With the ready form, we can focus on the heart of the module. We add a few functions to our Block, which will ultimately return a ready board with the structural data based on the schemas of, specifically on one type – the Product.

In brief:

  • getProduct() function will check if we are on the product’s page
  • by submitting the parameter in the form of attribute code to the getAttributeValue() function, we will receive its value.

Finally, we add the function, which will collect all of the product data into one table and return it in the JSON format.   Here is the complete content of the block:

The comments in the code define its individual parts, so there is no need to go into its details here.   Finally, let’s “spit” everything out to the template:

That’s all! We have just finished creating our module. Now, we should check if it works the way it is supposed to. Testing, testing, testing… Unfortunately, Google, Bing, or Yahoo have not provided any tools to view the search result supporting structural data from JSONLD, so we must wait for the effect until the bots index our products. However, there is a way to check if the information submitted by us is correct. We can use Google’s e-mail markup tester. Let’s open a random product in our store, copy the full source of the site, and paste our HTML into the tester. If we do everything right, we should obtain more or less the following result: 2014-05-30_1223

Right now, our module is not capable of providing complex support for configurable products and groups. It will only convey the information about the offer, which it will see on the page when it is displayed. A blue shirt can be more expensive than a white one, but in this case, we are unable to show this directly in the search engine. Perhaps I will expand this add-on in the future, but in the first version, I tried to respect the server and put as little load on it as possible. The download link for the add-on is here