Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Add Google Structured Data (formerly Rich Snippets) to your product pages Rate Topic   * * * * * 2 votes

 
  • preudomme
  • Junior Member
  • Members
  • Join Date: 03-Mar 09
  • 43 posts

Posted 18 March 2013 - 10:57 PM #1

* Updated to hooks & my_changes version. Check post #5 *

It's fairly easy actually

This is my case with v3.0.6, should be ok for v3.x.x and also should be ok for v2.x.x with maybe minor changes regarding the template file and what variables are used for pulled data, depending on your cart version.

This MOD includes one additional function.

1. Open /addons/discussions/controllers/customer/init.post.php

Add this function at the end of the file:

function fn_get_review_count($object_id,$object_type)
{
			global $db_tables;
			
			$discussion = fn_get_discussion($object_id, $object_type);
			
			if (empty($discussion)) {
				return false;
			}
			return db_get_field("SELECT COUNT(b.post_id) as val FROM ?:discussion_rating as a LEFT JOIN ?:discussion_posts as b ON a.post_id = b.post_id WHERE a.thread_id = ?i and b.status = 'A'", $discussion['thread_id']);						
}

2. Open up your product template .tpl file i.e:
/skins/YOUR_SKIN/customer/blocks/product_templates/default_template.tpl (may be different in your case)

Add this code right at the end of the file:

{assign var="product_amountN" value=$product.inventory_amount|default:$product.amount}
{assign var="url" value="`$config.current_location`/`$config.current_url`"|fn_url}
{assign var="average_rating" value=$product.product_id|fn_get_average_rating:"P"}
{assign var="rev_count" value=$product.product_id|fn_get_review_count:"P"}

<div style="display: none;" itemscope itemtype="http://schema.org/Product">
<span itemprop="name">{$product.product|unescape}</span>
	 <span itemprop="image">{$config.current_location}{$product.main_pair.detailed.image_path}</span>
  <img itemprop="image" src="{$config.current_location}{$product.main_pair.detailed.http_image_path}"/>
	 <span itemprop="description"> {$product.full_description}</span>
	 <span itemprop="url">{$url}</span>
	 <span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <span itemprop="price">{$product.price|format_price:$currencies.$primary_currency:''}</span>
   <meta itemprop="priceCurrency" content="YOUR_CURRENCY_CODE" />
   {if $product_amountN > 0}
		  <link itemprop="availability" href="http://schema.org/InStock">
   {else}
		  <link itemprop="availability" href="http://schema.org/OutOfStock">
   {/if}
  </span>
  <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
   <span itemprop="ratingValue">{$average_rating}</span>
	  <span itemprop="bestRating">5</span>
   <span itemprop="reviewCount">{$rev_count}</span>
	</div>
</div>

That's it!

Don't forget to change "YOUR_CURRENCY_CODE" (without the quotes) to your currency (EUR, USD etc)

You can check if it works for you from the google test page at: http://www.google.co...ls/richsnippets

Enjoy...

Edited by preudomme, 21 March 2013 - 09:02 PM.

2.1.4 / Live
4.2.1 / Devel

 

Posted 19 March 2013 - 01:38 AM #2

I just tried it and it appears to work perfectly!

Thank you preudomme
I've moved on from CS-Cart to WooC******** - If you need anything I can be of little help.

 
  • luandesign
  • Newbie
  • Members
  • Join Date: 25-Jul 11
  • 6 posts

Posted 20 March 2013 - 03:48 AM #3

thanks ! i love cs-cart

 
  • crazyshark20
  • Junior Member
  • Members
  • Join Date: 19-Aug 09
  • 310 posts

Posted 21 March 2013 - 11:34 AM #4

Thank you preudomme

 
  • preudomme
  • Junior Member
  • Members
  • Join Date: 03-Mar 09
  • 43 posts

Posted 21 March 2013 - 08:57 PM #5

Thank you all for trying out.

I posted this mod but then as I don't like core files modifications, I studied a little bit and figured out how to apply this mod with the lovely hooks and by the help of my_changes add-on.

Here is how it is

1. Create func.php in /addons/my_changes and paste this function in the file

<?php
if ( !defined('AREA') ) { die('Access denied'); }
/* FUNCTION REVIEW COUNT -- START */
function fn_my_changes_get_review_count($object_id,$object_type)
{
			global $db_tables;
			
			$discussion = fn_get_discussion($object_id, $object_type);
			
			if (empty($discussion)) {
				return false;
			}
			return db_get_field("SELECT COUNT(b.post_id) as val FROM ?:discussion_rating as a LEFT JOIN ?:discussion_posts as b ON a.post_id = b.post_id WHERE a.thread_id = ?i and b.status = 'A'", $discussion['thread_id']);						
}
/* FUNCTION - REVIEW COUNT -- END */
?>

2. Create /hooks directory (if not exists) in /skins/YOUR_SKIN/customer/addons/my_changes

3. Check the hook name used in your product details .tpl file. For "default_template.tpl" the hook is defined as:
{hook name="products:view_main_info"}

So our folder structure should be like this /skins/YOUR_SKIN/customer/addons/my_changes/hooks/products

4. Inside this folder create a file named "view_main_info.post.tpl" . We will add the rich snippets code after the "products:view_main_info" hook

5. Copy the following code in view_main_info.post.tpl

{** Rich Snippets - Product Schema - START **}
{*HTML microdata*}
{assign var="product_amountN" value=$product.inventory_amount|default:$product.amount}
{assign var="url" value="`$config.current_location`/`$config.current_url`"|fn_url}
{assign var="average_rating" value=$product.product_id|fn_get_average_rating:"P"}
{assign var="rev_count" value=$product.product_id|fn_my_changes_get_review_count:"P"}

<div style="display: none;" itemscope itemtype="http://schema.org/Product">
<span itemprop="name">{$product.product|unescape}</span>
	 <span itemprop="image">{$config.current_location}{$product.main_pair.detailed.image_path}</span>
  <img itemprop="image" src="{$config.current_location}{$product.main_pair.detailed.http_image_path}"/>
	 <span itemprop="description"> {$product.full_description}</span>
	 <span itemprop="url">{$url}</span>
	 <span itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <span itemprop="price">{$product.price|format_price:$currencies.$primary_currency:''}</span>
   <meta itemprop="priceCurrency" content="TRY" />
   {if $product_amountN > 0}
		  <link itemprop="availability" href="http://schema.org/InStock">
   {else}
	<link itemprop="availability" href="http://schema.org/OutOfStock">
   {/if}
  </span>
  <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
   <span itemprop="ratingValue">{$average_rating}</span>
	  <span itemprop="bestRating">5</span>
   <span itemprop="reviewCount">{$rev_count}</span>
	</div>
</div>
{** Rich Snippets - Product Schema - END **}

That's it. By using the hooks and my_changes technique it's possible to do anything without altering any core files.

Again don't forget to change YOUR_SKIN and currency code "TRY" to your desired values.

Cheers...
2.1.4 / Live
4.2.1 / Devel

 
  • kaelin
  • Junior Member
  • Members
  • Join Date: 05-Jan 09
  • 9 posts

Posted 25 March 2013 - 12:50 PM #6

wow - thanks so much - just what I was looking for. Followed your instructions exactly, but I'm not seeing the "YOUR_SKIN" to change? Implemented everything anyway - but am not seeing it show up on my product page...thanks for all the effort here.

 
  • johnbol1
  • Never Re
  • Members
  • Join Date: 23-Feb 10
  • 4673 posts

Posted 25 March 2013 - 01:02 PM #7

wow - thanks so much - just what I was looking for. Followed your instructions exactly, but I'm not seeing the "YOUR_SKIN" to change? Implemented everything anyway - but am not seeing it show up on my product page...thanks for all the effort here.


"yourskin" is your skin name. if you are on v3 then it will be skins/basic

John

Custom printed hi visibility clothing sale the UK's online hivis safety shop
v4.5.2


 
  • Gizmo
  • Junior Member
  • Members
  • Join Date: 05-Jan 09
  • 142 posts

Posted 02 April 2013 - 07:25 AM #8

Hook method doesnt seem to be working for me..
[center]www.vapeking.co.za[/center]

 
  • Gizmo
  • Junior Member
  • Members
  • Join Date: 05-Jan 09
  • 142 posts

Posted 02 April 2013 - 08:38 AM #9

Nevermind just had to clear cache. Anyway All my products show out of stock on the snippet. I do not use inventory for my store So would it be safe to remove this line - <link itemprop="availability" href="http://schema.org/OutOfStock">
[center]www.vapeking.co.za[/center]

 

Posted 03 April 2013 - 04:24 AM #10

Has anyone verified this works for V2.2.5 ?? Would love to get it working..

Elkhorn Graphics LLC
Cs-Cart 4.7.1  SP3


 
  • guyrotberg
  • Member
  • Members
  • Join Date: 14-Nov 09
  • 143 posts

Posted 26 April 2013 - 06:51 PM #11

Great mod. Does it work for 2.2.4?

 
  • preudomme
  • Junior Member
  • Members
  • Join Date: 03-Mar 09
  • 43 posts

Posted 21 May 2013 - 11:54 AM #12

Nevermind just had to clear cache. Anyway All my products show out of stock on the snippet. I do not use inventory for my store So would it be safe to remove this line - <link itemprop="availability" href="http://schema.org/OutOfStock">


Probably you have already tested it (as it's been over 1 month :-) )but it should be safe to do so.
2.1.4 / Live
4.2.1 / Devel

 
  • ThomH
  • Senior Member
  • Members
  • Join Date: 20-Nov 07
  • 1572 posts

Posted 21 May 2013 - 03:29 PM #13

Interesting mod.

WebGraphiq offers a wide range of professionally developed, ready to use CS-Cart add-ons to provide additional functionality and boost your sales. The oldest active CS-Cart add-on development team. -- Since 2006 --


CS-CART ADD-ONS | FREE QUOTE | CS-CART DEVELOPMENT | @webgraphiq


 
  • meetshamee
  • Advanced Member
  • Trial users
  • Join Date: 12-Feb 13
  • 92 posts

Posted 21 May 2013 - 06:57 PM #14

its working 3.4, thanks preudomme

 
  • Alecomp
  • Senior Member
  • Trial users
  • Join Date: 13-Jul 12
  • 342 posts

Posted 28 May 2013 - 11:28 AM #15

Hi
have v3.0.6 ultimate
cant understand this
3. Check the hook name used in your product details .tpl file. For "default_template.tpl" the hook is defined as:
{hook name="products:view_main_info"}

Should i find default_template.tpl and insert this {hook name="products:view_main_info"} ?

 
  • vmajor
  • Member
  • Members
  • Join Date: 08-Feb 10
  • 72 posts

Posted 05 August 2013 - 10:40 PM #16

This doesn't actually work with Google. The entire rich snippet markup is contained within a hidden content:

<div style="display: none;" itemscope itemtype="http://schema.org/Product">

Google refuses to display rich snippets if the snippet data is actually hidden from the page view - they do not care that it is the same data.

Specifically this is what they said:

Markup Type:Product
Hidden content: <div style="display: none;" itemscope="" itemtype="http://schema.org/Product">
This div which has the markup, is explicitly hidden using style="display: none;". The markup tags should be placed in the actual html tags surrounding the actual visible content. Please refer to the documentation at http://schema.org/Product.


...I do not see how this posted method can be made to comply as it relies entirely on generating additional dynamic content specifically for markup, then hiding it from the page. Anyone have any ideas?

V.

 
  • Stifler
  • Member
  • Members
  • Join Date: 18-Feb 13
  • 18 posts

Posted 19 August 2013 - 06:38 PM #17

As far as I know Google can ban permanently to display the snippets of such store. Don't think it's a good idea, especially as such modification doesn't cost so expensive now.

 
  • preudomme
  • Junior Member
  • Members
  • Join Date: 03-Mar 09
  • 43 posts

Posted 22 August 2013 - 02:17 PM #18

If this is the case, then it will be better to apply this as a "core mod" rather than a my_changes thing. What I don't understand is that the rich snippets test tool of google shows the preview with no errors or warnings like "div is hidden, please use the tags in the actual visible html tags". Anyway, those who are not happy with core modifications can of course go and buy an add-on.

Cheers
2.1.4 / Live
4.2.1 / Devel

 
  • Magpie Don
  • Senior Member
  • Members
  • Join Date: 01-Apr 09
  • 822 posts

Posted 22 August 2013 - 05:59 PM #19

I added the Rich Snippets data to a view_main_info.pre.tpl so it's appended prior to the product data. I placed the content in META tags as in this example:
<div itemscope itemtype="http://schema.org/Product">
<META itemprop="name" content="{$product.product|unescape}" />

The DIV tag is closed in the view_main_info.post template. But all the content tags are META tags, in the body of the HTML.

So far Google has indexed my pages and is including the Price, Stock and Aggregated Rating in my site's search results for products.
I made a change to the way I did this, and included Open Graph formatted content tags in the header of the store (for Facebook sharing correct product image and URL), but after re-indexing by Google, none of the Rich Snippet data was displayed in the Google search results. I removed the Open Graph tags from the header and after another Google crawl the Rich Snippets data is back in the search results.

I hope the use of meta tags doesn't jeopardize my relationship with Google.
It's really rather difficult to use an "in line method" to get the Aggregated Review data included in with the Discussions addon, and still be included in with the "schema.org/Product" div tag - so it is read as a sub-item under the "schema.org/Product" data where it should be.
If anyone has any experience opening a DIV tag in the product data, and closing it after the Discussion addon, or at least wrapping it around the Product name/price/stock and the Description, Reviews and Features in the product tabs, I'd be glad to hear it.

CS-Cart Ultimate ver 4.9.3 SP1


 
  • jalnicu
  • Advanced Member
  • Members
  • Join Date: 17-Sep 13
  • 72 posts

Posted 15 January 2014 - 03:00 PM #20

It's working on the google testing tool, but it's more than one month and google refuse to display rich snippets.
It's working for somebody?

CS-Cart 4.3.4