Skip to content

Instantly share code, notes, and snippets.

@yoanmarchal
Last active February 21, 2022 22:19
Show Gist options
  • Save yoanmarchal/eeb267a08664987bf86949beafd64fe9 to your computer and use it in GitHub Desktop.
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 **}
@Aldegunde
Copy link

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

@yoanmarchal
Copy link
Author

@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

@Aldegunde
Copy link

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.

<label

Thanks for oyur comments

@Aldegunde
Copy link

<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

@Aldegunde
Copy link

Sorry @yoanmarchal, definetly I was doing something worng, sorry for that. I was looking on worng place...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment