Files
season/snippets/product-structured-data.liquid

113 lines
5.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{%- comment -%}
Product JSON-LD for Google rich results / merchant listings.
Adds aggregateRating (reviews.* metafields), shippingDetails and hasMerchantReturnPolicy
(theme settings › SEO) on top of the data Shopify's structured_data filter provides.
{%- endcomment -%}
{%- liquid
assign currency = cart.currency.iso_code
assign country = settings.sd_ship_country | default: 'MX' | upcase
assign ship_cost = settings.sd_ship_cost | default: 0
assign free_from = settings.sd_free_threshold | default: 0 | times: 100
assign product_url = request.origin | append: product.url
assign current = product.selected_or_first_available_variant
assign rating_count = product.metafields.reviews.rating_count.value | default: 0 | plus: 0
assign rating_value = product.metafields.reviews.rating.value.rating | default: 0
assign rating_best = product.metafields.reviews.rating.value.scale_max | default: 5
assign rating_worst = product.metafields.reviews.rating.value.scale_min | default: 1
assign brand = product.vendor | default: shop.name
-%}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Product",
"@id": {{ product_url | append: '#product' | json }},
"url": {{ product_url | json }},
"name": {{ product.title | json }},
"description": {{ product.description | strip_html | strip | truncate: 5000 | json }},
{%- if product.media.size > 0 %}
"image": [
{%- assign img_n = 0 -%}
{%- for media in product.media -%}
{%- if media.preview_image and img_n < 6 -%}
{%- if img_n > 0 %},{% endif -%}
{{ media.preview_image | image_url: width: 1920 | prepend: 'https:' | json }}
{%- assign img_n = img_n | plus: 1 -%}
{%- endif -%}
{%- endfor -%}
],
{%- endif %}
"brand": { "@type": "Brand", "name": {{ brand | json }} },
{%- if product.type != blank %}
"category": {{ product.type | json }},
{%- endif %}
{%- if current.sku != blank %}
"sku": {{ current.sku | json }},
{%- endif %}
{%- if rating_count > 0 and rating_value != 0 %}
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": {{ rating_value | json }},
"bestRating": {{ rating_best | json }},
"worstRating": {{ rating_worst | json }},
"ratingCount": {{ rating_count }},
"reviewCount": {{ rating_count }}
},
{%- endif %}
"offers": [
{%- for variant in product.variants -%}
{%- liquid
assign v_price = variant.price | divided_by: 100.0
assign v_rate = ship_cost
if free_from > 0 and variant.price >= free_from
assign v_rate = 0
endif
assign gtin_len = variant.barcode | size
-%}
{
"@type": "Offer",
"@id": {{ product_url | append: '?variant=' | append: variant.id | append: '#offer' | json }},
"url": {{ product_url | append: '?variant=' | append: variant.id | json }},
{%- if variant.sku != blank %}
"sku": {{ variant.sku | json }},
{%- endif %}
{%- if variant.barcode != blank and gtin_len >= 8 and gtin_len <= 14 %}
"gtin": {{ variant.barcode | json }},
{%- endif %}
{%- unless product.has_only_default_variant %}
"name": {{ product.title | append: ' - ' | append: variant.title | json }},
{%- endunless %}
"price": {{ v_price | round: 2 | json }},
"priceCurrency": {{ currency | json }},
"itemCondition": "https://schema.org/NewCondition",
"availability": "https://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}",
"seller": { "@type": "Organization", "name": {{ shop.name | json }} },
"shippingDetails": {
"@type": "OfferShippingDetails",
"shippingRate": { "@type": "MonetaryAmount", "value": {{ v_rate | json }}, "currency": {{ currency | json }} },
"shippingDestination": { "@type": "DefinedRegion", "addressCountry": {{ country | json }} },
"deliveryTime": {
"@type": "ShippingDeliveryTime",
"handlingTime": { "@type": "QuantitativeValue", "minValue": {{ settings.sd_handling_min | default: 1 }}, "maxValue": {{ settings.sd_handling_max | default: 2 }}, "unitCode": "DAY" },
"transitTime": { "@type": "QuantitativeValue", "minValue": {{ settings.sd_transit_min | default: 3 }}, "maxValue": {{ settings.sd_transit_max | default: 5 }}, "unitCode": "DAY" }
}
},
"hasMerchantReturnPolicy": {
"@type": "MerchantReturnPolicy",
"applicableCountry": {{ country | json }},
{%- if settings.sd_returns %}
"returnPolicyCategory": "https://schema.org/MerchantReturnFiniteReturnWindow",
"merchantReturnDays": {{ settings.sd_return_days | default: 5 }},
"returnMethod": "https://schema.org/ReturnByMail",
"refundType": "https://schema.org/{{ settings.sd_refund_type | default: 'ExchangeRefund' }}",
"returnFees": "https://schema.org/{{ settings.sd_return_fees | default: 'FreeReturn' }}",
"merchantReturnLink": {{ request.origin | append: '/policies/refund-policy' | json }}
{%- else %}
"returnPolicyCategory": "https://schema.org/MerchantReturnNotPermitted"
{%- endif %}
}
}{% unless forloop.last %},{% endunless %}
{%- endfor %}
]
}
</script>