{% sw_extends '@Storefront/storefront/page/product-detail/meta.html.twig' %}
{% block layout_head_canonical %}
{% set canonicalUrl = page.product.id %}
{% if page.product.canonicalProductId %}
{% set canonicalUrl = page.product.canonicalProductId %}
{% endif %}
{% set FirstVariant = getFirstId(page.product.parentId,context.context) %}
{% if FirstVariant.id %}
<link rel="canonical" href="{{ seoUrl('frontend.detail.page', { productId: FirstVariant.id }) }}">
{% else %}
<link rel="canonical" href="{{ seoUrl('frontend.detail.page', { productId: canonicalUrl }) }}">
{% endif %}
{% endblock %}