-
-
Save yoanmarchal/eeb267a08664987bf86949beafd64fe9 to your computer and use it in GitHub Desktop.
{* Structured Data Json - LD Microdata for Prestashop 1.6.X & 1.7 | |
* | |
* Add this code in your smarty global.tpl/header.tpl file to show Organization, WebPage, Website and Product Microdata in ld+json format. | |
* Requires Prestashop 'productcomments' module for review stars ratings. | |
* by Ruben Divall @rubendivall http://www.rubendivall.com | |
* Module by @atomiksoft: https://addons.prestashop.com/en/seo-natural-search-engine-optimization/24511-microformats-in-ldjson.html | |
*} | |
<script type="application/ld+json"> | |
{ | |
"@context" : "http://schema.org", | |
"@type" : "Organization", | |
"name" : "{$shop_name|escape:'html':'UTF-8'}", | |
"url" : "{$link->getPageLink('index', true)|escape:'html':'UTF-8'}", | |
"logo" : { | |
"@type":"ImageObject", | |
"url":"{$logo_url|escape:'html':'UTF-8'}" | |
} | |
} | |
</script> | |
<script type="application/ld+json"> | |
{ | |
"@context":"http://schema.org", | |
"@type":"WebPage", | |
"isPartOf": { | |
"@type":"WebSite", | |
"url": "{$link->getPageLink('index', true)|escape:'html':'UTF-8'}", | |
"name": "{$shop_name|escape:'html':'UTF-8'}" | |
}, | |
"name": "{$meta_title|escape:'html':'UTF-8'}", | |
"url": "{if isset($force_ssl) && $force_ssl}{$base_dir_ssl|escape:'html':'UTF-8'}{trim($smarty.server.REQUEST_URI,'/')|escape:'html':'UTF-8'}{else}{$base_dir|escape:'html':'UTF-8'}{trim($smarty.server.REQUEST_URI,'/')|escape:'html':'UTF-8'}{/if}" | |
} | |
</script> | |
{if $page_name =='index'} | |
<script type="application/ld+json"> | |
{ | |
"@context": "http://schema.org", | |
"@type": "WebSite", | |
"url": "{$link->getPageLink('index', true)|escape:'html':'UTF-8'}", | |
"image": { | |
"@type": "ImageObject", | |
"url": "{$logo_url|escape:'html':'UTF-8'}" | |
}, | |
"potentialAction": { | |
"@type": "SearchAction", | |
"target": "{'--search_term_string--'|str_replace:'{search_term_string}':$link->getPageLink('search',true,null,['search_query'=>'--search_term_string--'])}", | |
"query-input": "required name=search_term_string" | |
} | |
} | |
</script> | |
{/if} | |
{if $page_name == 'product'} | |
<script type="application/ld+json"> | |
{ | |
"@context": "http://schema.org/", | |
"@type": "Product", | |
"name": "{$product->name|escape:'html':'UTF-8'}", | |
"description": "{$product->description_short|strip_tags|escape:'html':'UTF-8'}", | |
{if $product->reference}"mpn": "{$product->id|escape:'html':'UTF-8'}",{/if} | |
{if $product_manufacturer->name}"brand": { | |
"@type": "Thing", | |
"name": "{$product_manufacturer->name|escape:'html':'UTF-8'}" | |
},{/if} | |
{if isset($nbComments) && $nbComments && $ratings.avg}"aggregateRating": { | |
"@type": "AggregateRating", | |
"ratingValue": "{$ratings.avg|round:1|escape:'html':'UTF-8'}", | |
"reviewCount": "{$nbComments|escape:'html':'UTF-8'}" | |
},{/if} | |
{if empty($combinations)} | |
"offers": { | |
"@type": "Offer", | |
"priceCurrency": "{$currency->iso_code|escape:'html':'UTF-8'}", | |
"name": "{$product->name|escape:'html':'UTF-8'}", | |
"price": "{$product->getPrice(true, $smarty.const.NULL, 2)|round:'2'|escape:'html':'UTF-8'}", | |
"image": "{$link->getImageLink($product->link_rewrite, $cover.id_image, 'home_default')|escape:'html':'UTF-8'}", | |
{if $product->ean13} | |
"gtin13": "{$product->ean13|escape:'html':'UTF-8'}", | |
{else if $product->upc} | |
"gtin13": "0{$product->upc|escape:'html':'UTF-8'}", | |
{/if} | |
"sku": "{$product->reference}", | |
{if $product->condition == 'new'}"itemCondition": "http://schema.org/NewCondition",{/if} | |
{if $product->condition == 'used'}"itemCondition": "http://schema.org/UsedCondition",{/if} | |
{if $product->condition == 'refurbished'}"itemCondition": "http://schema.org/RefurbishedCondition",{/if} | |
"availability":{if $product->quantity > 0} "http://schema.org/InStock"{else} "http://schema.org/OutOfStock"{/if}, | |
"seller": { | |
"@type": "Organization", | |
"name": "{$shop_name|escape:'html':'UTF-8'}" | |
} | |
} | |
{else} | |
"offers": [ | |
{foreach key=atomik item=combination from=$combinations} | |
{ | |
"@type": "Offer", | |
"name": "{$product->name|escape:'html':'UTF-8'} - {$combination.reference}", | |
"priceCurrency": "{$currency->iso_code|escape:'html':'UTF-8'}", | |
"price": "{$combination.finalprice|round:'2'}", | |
"image": "{if $combination.id_image > 0}{$link->getImageLink($product->link_rewrite, $combination.id_image, 'home_default')|escape:'html':'UTF-8'}{else}{$link->getImageLink($product->link_rewrite, $cover.id_image, 'home_default')|escape:'html':'UTF-8'}{/if}", | |
{if $combination.ean13} | |
"gtin13": "{$combination.ean13|escape:'html':'UTF-8'}", | |
{else if $combination.upc} | |
"gtin13": "0{$combination.upc|escape:'html':'UTF-8'}", | |
{/if} | |
"sku": "{$combination.reference}", | |
{if $combination.condition == 'new'}"itemCondition": "http://schema.org/NewCondition",{/if} | |
{if $combination.condition == 'used'}"itemCondition": "http://schema.org/UsedCondition",{/if} | |
{if $combination.condition == 'refurbished'}"itemCondition": "http://schema.org/RefurbishedCondition",{/if} | |
"availability": {if $combination.quantity > 0}"http://schema.org/InStock"{else}"http://schema.org/OutOfStock"{/if}, | |
"seller": { | |
"@type": "Organization", | |
"name": "{$shop_name|escape:'html':'UTF-8'}"} | |
} {if !$combination@last},{/if} | |
{/foreach} | |
] | |
{/if} | |
} | |
</script> | |
{/if} | |
{** End of Structured Data Json - LD Microdata for Prestashop 1.6.X **} |
i found that https://gist.github.com/sen0rxol0/1b411bccfc643dc87f551c2f8578bb94 by looking at fork of this gist
Hi Yoan,
Thank you for your help. I followed your link and tested the modifications without effect. Everything works fine for microdata but not for ld+json, where "offers", "review", or "aggregateRating", "ratingCount", "reviewCount" or "ratingValue" errors still persist.
By the way, the Google Structured Data Testing Tool results are far away from the Google Search Console results (these are plenty of errors when the others are mostly clean).
If anyone has any idea, I'll be very happy to read it and help
@evamariamontero from what I was able to find, there is some suggestion to omit those parts of the Schema if there are no values to add. For e.g. if a product has no reviews, simply don't have it in the Schema. However, I have seen Google people working on the Schema implementation comment on some places, to use a null
value, but I am yet to try, or see an example of how to properly add those.
Hi all, asking for help,
Not usre why code do not works showing the brand on product pages:
https://delica-te-zen.com/te-verde/te-verde-gunpowder-templo-del-cielo
I understand that part of the code doing that is:
{if $product_manufacturer->name}"brand": {
"@type": "Thing",
"name": "{$product_manufacturer->name|escape:'html':'UTF-8'}"
}
But no sucess showing the brand. Shop is 1.7, any idea?
Thanks in advance. BR
@Aldegunde is your $product_manufacturer variable is available in this context ?
is your product manufacturer is set on the back office ?
FYI i'm not sure this code is able to work on 1.7 since it's a convenient fork of code taken from
Hi @yoanmarchal if I analyse the page on google search, there is an error on brand, but on the code I can see that content is clearly visible. Not sure why it is not shown.
Thanks for oyur comments
<meta itemprop="brand" content="Delica-Té-Zen (A)"><div class="product-manufacturer "> <label class="label">Marca</label> <span> <a href="https://delica-te-zen.com/brand/delica-te-zen-a">Delica-Té-Zen (A)</a> </span></div><div class="product-reference"> <label
Sorry @yoanmarchal, definetly I was doing something worng, sorry for that. I was looking on worng place...
Hi guys!
Thank you for the contribution. But I added the code first to global.tpl, then to header.tpl (1.6.1.24), without effect on the search console errors related to Either "offers", "review", or "aggregateRating", "ratingCount", "reviewCount" or "ratingValue".
Any hint on how to solve it?
Thank you so much!