← Alle Beiträge

Prestashop Product JSONLD with HasVariants

Prestashop 8.2: Missing JSON-LD Support for Combination Products and How to Fix It

While working with Prestashop 8.2, I noticed an issue that can negatively impact SEO for stores using product combinations (variants such as size, color, etc.).

By default, Prestashop generates JSON-LD structured data for product pages, but combination products are not handled properly. The standard product-jsonld.tpl file does not provide sufficient structured data for variants, meaning Google often cannot generate rich snippets because the necessary information is simply missing.

This can result in:

  • Missing price information in search results
  • Missing availability data in Google
  • Reduced visibility in rich results
  • Lower click-through rates (CTR)

The issue originates from the product-jsonld.tpl template file. The default implementation does not properly describe the relationship between a parent product and its variants. Search engines expect variant information to be included through properties such as hasVariant, allowing them to understand that a product may exist in multiple versions with different prices, stock levels, SKUs, or attributes.

The fix is straightforward: replace or override the default product-jsonld.tpl file with a customized version that adds support for hasVariant. The modified file should be placed in your theme’s /templates/_partials/microdata directory.

It is a bigger change and can have a noticeable impact on how Google understands your products and whether rich snippets are generated for combination products.

After applying the change, I strongly recommend testing the output with Google’s structured data tools:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
{*
 * Product JSON-LD incl. hasVariant, Shipping, Return Policy, Combo Images, additionalProperty,
 * dynamic DeliveryTime & Robust Truncated Variant Names 
  * PrestaShop 8.2 / v0.9
 *}

{assign var=hasAggregateRating value=false}

{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}

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

{assign var=hasWeight value=false}
{if isset($product.weight) && $product.weight != 0}
    {assign var=hasWeight value=true}
{/if}

{assign var=hasCombinations value=isset($combinations) && $combinations|count > 0}

{* Dynamische Extraktion von Lieferzeit und Umrechnung auf Tage *}
{assign var="stock_text" value=$product.available_now|default:$product.availability_message|default:''|lower}

{assign var="has_delivery_time" value=true}
{assign var="delivery_min" value=1}
{assign var="delivery_max" value=3}
{assign var="is_weeks" value=false}

{if $stock_text|strstr:'auf anfrage' || $stock_text|strstr:'anfrage'}
    {* Bei "Auf Anfrage" gibt es keine feste Lieferzeit -> shippingDetails komplett ausblenden *}
    {assign var="has_delivery_time" value=false}
{else}
    {if $stock_text|strstr:'woche' || $stock_text|strstr:'week'}
        {assign var="is_weeks" value=true}
    {/if}

    {* Alle Ziffern aus dem Text extrahieren *}
    {assign var="clean_nums" value=$stock_text|regex_replace:'/[^0-9]/':''}
    {if $clean_nums|strlen >= 2}
        {assign var="delivery_min" value=$clean_nums[0]}
        {assign var="delivery_max" value=$clean_nums[1]}
    {elseif $clean_nums|strlen == 1}
        {assign var="delivery_min" value=$clean_nums[0]}
        {assign var="delivery_max" value=$clean_nums[0]}
    {else}
        {assign var="has_delivery_time" value=false}
    {/if}

    {* Falls Wochen angegeben sind: mal 7 rechnen für valide Tage *}
    {if $is_weeks && $has_delivery_time}
        {assign var="delivery_min" value=$delivery_min * 7}
        {assign var="delivery_max" value=$delivery_max * 7}
    {/if}
{/if}

<script type="application/ld+json">
{
"@context":"https://schema.org/",
"@type": "{if $hasCombinations}ProductGroup{else}Product{/if}",

"name":"{$product.name|truncate:128:'...':true|escape:'html':'UTF-8'}",

"description":"{$page.meta.description|regex_replace:"/[\r\n]/":" "|escape:'html':'UTF-8'}",

"url":"{$product.canonical_url nofilter}",

{if !empty($product.cover)}
"image":"{$product.cover.bySize.large_default.url}",
{/if}

"category":"{$product.category_name|escape:'html':'UTF-8'}"

{if $product_manufacturer->name OR $shop.name},
"brand":{
    "@type":"Brand",
    "name":"{if $product_manufacturer->name}{$product_manufacturer->name|escape:'html':'UTF-8'}{else}{$shop.name|escape:'html':'UTF-8'}{/if}"
}
{/if}

{if $hasAggregateRating},
"aggregateRating":{
    "@type":"AggregateRating",
    "ratingValue":"{$ratingValue|round:1}",
    "reviewCount":"{$ratingReviewCount}"
}
{/if}

{if $hasWeight},
"weight":{
    "@type":"QuantitativeValue",
    "value":"{$product.weight}",
    "unitCode":"{$product.weight_unit}"
}
{/if}

{if $hasCombinations}
, "productGroupID": "{$product.id}"
, "hasVariant": [
    {assign var=first_comb value=true}
    {foreach from=$combinations item=c name=comb_loop}
    {if $c.price > 0}
    {if !$first_comb},{/if}
    {assign var=first_comb value=false}
    {
        "@type": "Product",
        {capture name="variant_name"}{$product.name}{if isset($c.attribute_designation) && !empty($c.attribute_designation)} - {$c.attribute_designation}{elseif isset($c.attributes_values) && $c.attributes_values|count > 0}{foreach from=$c.attributes_values item=attr} - {$attr}{/foreach}{/if}{/capture}
        "name": "{$smarty.capture.variant_name|regex_replace:"/\s+/" :" "|trim|truncate:128:'...':true|escape:'html':'UTF-8'}",
        "description": "{$page.meta.description|regex_replace:"/[\r\n]/":" "|escape:'html':'UTF-8'}",
        "sku": "{$c.reference|escape:'html':'UTF-8'}",
        "mpn": "{if $c.mpn}{$c.mpn|escape:'html':'UTF-8'}{else}{$c.reference|escape:'html':'UTF-8'}{/if}",
        {if !empty($c.ean13)}
        "gtin13": "{$c.ean13}",
        {/if}
        "image": {if !empty($c.images)}{foreach from=$c.images item=img name=img_loop}{if $smarty.foreach.img_loop.first}"{$img.bySize.large_default.url}"{/if}{/foreach}{elseif !empty($c.id_image) && $c.id_image > 0}"{$urls.shop_domain_url}/{$c.id_image}-large_default/{$product.link_rewrite}.jpg"{elseif !empty($product.cover)}"{$product.cover.bySize.large_default.url}"{else}""{/if},
        
        {if isset($c.attributes) && $c.attributes|count > 0}
        "additionalProperty": [
            {assign var=first_prop value=true}
            {foreach from=$c.attributes item=attr_id}
                {assign var=found_group_name value=""}
                {assign var=found_val_name value=""}
                
                {if isset($groups)}
                    {foreach from=$groups item=grp}
                        {if isset($grp.attributes[$attr_id])}
                            {assign var=found_group_name value=$grp.name}
                            {assign var=found_val_name value=$grp.attributes[$attr_id].name}
                        {/if}
                    {/foreach}
                {/if}
                
                {if !empty($found_group_name) && !empty($found_val_name)}
                    {if !$first_prop},{/if}
                    {assign var=first_prop value=false}
                    {
                        "@type": "PropertyValue",
                        "name": "{$found_group_name|escape:'html':'UTF-8'}",
                        "value": "{$found_val_name|escape:'html':'UTF-8'}"
                    }
                {/if}
            {/foreach}
        ],
        {/if}

        "offers": {
            "@type": "Offer",
            "price": "{$c.price}",
            "priceCurrency": "{$currency.iso_code}",
            {assign var=comb_list value=$c.list|replace:"'":""|replace:",":"/"}
            "url": "{$product.canonical_url nofilter}#/{$comb_list}",
            "validFrom": "{$smarty.now|date_format:'%Y-%m-%d'}",
            "priceValidUntil": "{($smarty.now+(60*60*24*365))|date_format:'%Y-%m-%d'}",
            "availability": "{if $c.quantity > 0}https://schema.org/InStock{else}https://schema.org/OutOfStock{/if}",
            "eligibleTransactionVolume": {
                "@type": "PriceSpecification",
                "price": "90.00",
                "priceCurrency": "EUR"
            },
            "seller": {
                "@type": "Organization",
                "name": "{$shop.name|escape:'html':'UTF-8'}"
            },
            "hasMerchantReturnPolicy": {
                "@type": "MerchantReturnPolicy",
                "applicableCountry": "DE",
                "returnPolicyCategory": "https://schema.org/MerchantReturnNotPermitted"
            }
            {if $has_delivery_time}
            , "shippingDetails": {
                "@type": "OfferShippingDetails",
                "shippingRate": {
                    "@type": "MonetaryAmount",
                    "value": "0.00",
                    "currency": "EUR"
                },
                "shippingDestination": {
                    "@type": "DefinedRegion",
                    "addressCountry": "DE"
                },
                "deliveryTime": {
                    "@type": "ShippingDeliveryTime",
                    "handlingTime": {
                        "@type": "QuantitativeValue",
                        "minValue": 0,
                        "maxValue": 1,
                        "unitCode": "DAY"
                    },
                    "transitTime": {
                        "@type": "QuantitativeValue",
                        "minValue": {$delivery_min},
                        "maxValue": {$delivery_max},
                        "unitCode": "DAY"
                    }
                }
            }
            {/if}
        }
    }
    {/if}
    {/foreach}
]
{elseif $product.price_amount > 0}
, "offers": {
    "@type": "Offer",
    "price": "{$product.price_amount}",
    "priceCurrency": "{$currency.iso_code}",
    "url": "{$product.canonical_url nofilter}",
    "validFrom": "{$smarty.now|date_format:'%Y-%m-%d'}",
    "priceValidUntil": "{($smarty.now+(60*60*24*365))|date_format:'%Y-%m-%d'}",
    "image": {if !empty($product.cover)}"{$product.cover.bySize.large_default.url}"{else}""{/if},
    "sku": "{$product.reference|escape:'html':'UTF-8'}",
    "mpn": "{if !empty($product.mpn)}{$product.mpn|escape:'html':'UTF-8'}{else}{$product.reference|escape:'html':'UTF-8'}{/if}",
    {if !empty($product.ean13)}
    "gtin13": "{$product.ean13}",
    {/if}
    "availability": "{$product.seo_availability}",
    "eligibleTransactionVolume": {
        "@type": "PriceSpecification",
        "price": "90.00",
        "priceCurrency": "EUR"
    },
    "seller": {
        "@type": "Organization",
        "name": "{$shop.name|escape:'html':'UTF-8'}"
    },
    "hasMerchantReturnPolicy": {
        "@type": "MerchantReturnPolicy",
        "applicableCountry": "DE",
        "returnPolicyCategory": "https://schema.org/MerchantReturnNotPermitted"
    }
    {if $has_delivery_time}
    , "shippingDetails": {
        "@type": "OfferShippingDetails",
        "shippingRate": {
            "@type": "MonetaryAmount",
            "value": "0.00",
            "currency": "EUR"
        },
        "shippingDestination": {
            "@type": "DefinedRegion",
            "addressCountry": "DE"
        },
        "deliveryTime": {
            "@type": "ShippingDeliveryTime",
            "handlingTime": {
                "@type": "QuantitativeValue",
                "minValue": 0,
                "maxValue": 1,
                "unitCode": "DAY"
            },
            "transitTime": {
                "@type": "QuantitativeValue",
                "minValue": {$delivery_min},
                "maxValue": {$delivery_max},
                "unitCode": "DAY"
            }
        }
    }
    {/if}
}
{/if}

}
</script>
#code#google shopping#hasvariants#jasonld#prestashop#prestashop 8.2#rich snippets
Diese Website verwendet keine Cookies. Weitere Informationen finden Sie in der Datenschutzerklärung.