Skip to content

Instantly share code, notes, and snippets.

@sen0rxol0
Forked from caovillanueva/product.tpl
Last active July 11, 2019 14:21
Show Gist options
  • Save sen0rxol0/1b411bccfc643dc87f551c2f8578bb94 to your computer and use it in GitHub Desktop.
Save sen0rxol0/1b411bccfc643dc87f551c2f8578bb94 to your computer and use it in GitHub Desktop.
[SEO for PS VER.] #PS16 #SEO
<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'}",
"image": [
{if isset($images)}{foreach from=$images item=image name=imagesProduct}
{assign var=imageIds value=$product->id|cat:'-'|cat:$image.id_image}
"{$link->getImageLink($product->link_rewrite, $imageIds, 'home_default')|escape:'html':'UTF-8'}"{if $smarty.foreach.imagesProduct.last}{else},{/if}
{/foreach}{/if}
],
"description": "{$product->description_short|strip_tags|escape:'html':'UTF-8'}",
{if $product->reference}"mpn": "{$product->id|escape:'html':'UTF-8'}",{/if}
{if $product->reference}"sku": "{$product->reference|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",
"url": "{$link->getProductLink($product)}",
"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'}",
"priceValidUntil": "{'Y'|date}-12-31",
"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=id_product_combination item=combination from=$combinations}
{
"@type": "Offer",
"url": "{$link->getProductLink($product)}",
"name": "{$product->name|escape:'html':'UTF-8'} - {$combination.reference}",
"priceCurrency": "{$currency->iso_code|escape:'html':'UTF-8'}",
"price": "{Product::getPriceStatic($product->id, true, $id_product_combination)|round:'2'}",
"priceValidUntil": "{'Y'|date}-12-31",
"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}
1. Only 1 tag of product shoulb be exist.
<p class="our_price_display" itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<meta itemprop="priceValidUntil" content="{'Y'|date}-12-31" />
<meta itemprop="url" content="{$link->getProductLink($product)}">
</p>
<div itemprop="brand" itemscope itemtype="http://schema.org/Brand">
<meta itemprop="name" content="{$product_manufacturer->name}">
</div>
{if !empty($product->reference) && $product->reference}
<meta itemprop="mpn" content="{$product->reference}" /> <!-- If not have mpn, use the reference val. -->
{/if}
#######IF THE CODE CAME FROM ANY MODULE THAT NOT HAVE TAGS:
<meta itemprop="availability" content="{$priceDisplay}" />
<!-- Put out of Offer block. -->
<meta itemprop="brand" content="{$product.manufacturer_name}" />
<meta itemprop="sku" content="{$product.reference}" />
{if !empty($product.reference) && $product.reference}
<meta itemprop="mpn" content="{$product.reference}" />
{/if}
<meta itemprop="description" content="{$product.description|strip_tags}" />
FOR PRESTASHOP 1.6.XX
<meta itemprop="brand" content="{$product->manufacturer_name}" />
<meta itemprop="description" content="{$product->description|strip_tags}" />
If warning for "ratingValue" when no reviews in product. Just ommit aggregate Rarting
FOR PRESTASHOP 1.6.XX
Before:
<div id="product_comments_block_extra" class="no-print col-sm-5" itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
After:
<div id="product_comments_block_extra" class="no-print col-sm-5" {if $nbComments != 0} itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating"{/if}>
Add this one if apply,avoid "One of ratingCount or reviewCount must be provided.":
<meta itemprop="reviewCount" content = "{$nbComments}" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment