Skip to content

Commit

Permalink
Merge views subtree
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed May 12, 2023
2 parents 0916e3c + 1cbfdbf commit 13e3b72
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion template/pages/@/sections/product-block.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (stamps && Array.isArray(stamps.stamps_list) && stamps.stamps_list.length) {
stampsList = stamps.stamps_list
}
%>

<div id="product-block" class="product-block my-4 mb-lg-5">
<div class="container">
<section
Expand Down Expand Up @@ -237,6 +238,23 @@ if (_.state.gtin && _.state.gtin[0]) {
productJsonLd.gtin = _.state.gtin[0]
}
%>
<script type="application/ld+json"><%-
<script id="product-block-jsonld" type="application/ld+json"><%-
JSON.stringify(productJsonLd)
%></script>
<script type="text/javascript">
setTimeout(() => {
const urlParams = new URLSearchParams(window.location.search);
const variationId = urlParams.get('variation_id');
const variations = window.storefront.context.body && window.storefront.context.body.variations;
if (Array.isArray(variations) && variationId) {
const selectedVariation = variations.find(variation => variation._id === variationId);
if (selectedVariation) {
const $jsonLd = document.querySelector('#product-block-jsonld');
const jsonLd = JSON.parse($jsonLd.innerText);
jsonLd.sku = selectedVariation.sku;
jsonLd.offers.price = selectedVariation.price;
document.querySelector('#product-block-jsonld').innerText = JSON.stringify(jsonLd);
}
}
}, 100);
</script>

0 comments on commit 13e3b72

Please sign in to comment.