How to handle the review rich snippets with my theme?

The purpose of this FAQ is to help you set up the rich snippets of the reviews published on your store.

By default, PrestaShop doesn't manage this markup, that's why it is necessary to modify some code.

First of all:

  1. Verify you have a version of the module higher than or equal to 5.0.3. If this is not the case, update your module.
  2. All changes have to be done in the template: themes/your_theme/templates/_partials/microdata/product-jsonld.tpl Remember to make a backup of your original file to be able to roll back if necessary.

 

Step 1

Replace the following code:

{if !empty($product.productComments.averageRating) && !empty($product.productComments.nbComments)}
  {assign var=hasAggregateRating value=true}
  {assign var=ratingValue value=$product.productComments.averageRating}
  {assign var=ratingReviewCount value=$product.productComments.nbComments}
{/if}

by:

{if !empty($product.productComments.averageRating) && !empty($product.productComments.nbComments)}
  {assign var=hasAggregateRating value=true}
  {assign var=ratingValue value=$product.productComments.averageRating}
  {assign var=ratingReviewCount value=$product.productComments.nbComments}
  {assign var=reviews value=$product.productComments.reviews}
{/if}

to assign reviews that come from the module.

In fact, we've just added the line:

{assign var=reviews value=$product.productComments.reviews}

 

Step 2

Replace the following code:

    {if $hasAggregateRating},
      "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": "{$ratingValue|round:1|escape:'html':'UTF-8'}",
        "reviewCount": "{$ratingReviewCount|escape:'html':'UTF-8'}"
        } 
{/if}

by:

    {if $hasAggregateRating},
      "aggregateRating": {
        "@type": "AggregateRating",
        "ratingValue": "{$ratingValue|round:1|escape:'html':'UTF-8'}",
        "reviewCount": "{$ratingReviewCount|escape:'html':'UTF-8'}"
      }
      {if $reviews}
      ,
      "review": [
        {foreach from=$reviews item=comment}
          {if $comment.content}
            {
              "@type": "Review",
              "author": {
                "@type": "Person",
                "name": "{$comment.customer_name|escape:'html':'UTF-8'}"
              },
              "datePublished": "{$comment.date_add|escape:'html':'UTF-8'|substr:0:10}",
              "reviewRating": {
                "@type": "Rating",
                "description": "{$comment.content|nl2br nofilter}",
                "ratingValue": "{$comment.grade|escape:'html':'UTF-8'}",
                "bestRating": "5",
                "worstRating": "1"
              }
            {if $comment@last}
                }
            {else}
              },
            {/if}
          {/if}
        {/foreach}
      ]
      {/if}
    {/if}

This will allow the review management in the JSON-TLD, and it will make the data available to Google.

Other FAQs in this category