Hello, I’m working on a project using the Shopify plugin.
I’ve successfully implemented most of the features following the Shopify plugin manual, but I’m having trouble with the Buy Button; it’s not working.
Is there anyone who can help me with this issue?
Here are the error details and the code…!
*** For reference, there are no issues with the domain and storefrontAccessToken.
Link: https://1-2-3-4-5.studio/typeface/products/yoonseul-batang
/templates/shopify.product.php
<!-- Display values with Kirby if you want -->
<img src="<?= $page->shopifyFeatured() ?>" />
<?= $page->yourCustomField() ?>
<?= $page->shopifyPrice() ?>
<?= $page->shopifyDescriptionHTML() ?>
<?= $page->shopifyType() ?>
<?= $page->shopifyVendor() ?>
<!-- Shopify Product Button -->
<div id="product-component-<?= $productID ?>"></div>
<?php foreach ($page->shopifyTags()->split(',') as $key => $tag): ?>
<?= $tag ?>
<?php endforeach ?>
/snippets/Footer.php
<script>
<?php
// PHP variables for Shopify product data
$producttitle = $page->shopifyTitle();
$producttext = $page->shopifyDescriptionHTML();
$productimage = $page->shopifyFeaturedImage();
$productID = $page->shopifyID();
$productprice = $page->shopifyPrice();
$productbuttontext = 'Buy Now';
$productimagealt = $producttitle;
?>
</script>
<div id="product-component-<?= $productID ?>"></div>
<script src="https://sdks.shopifycdn.com/buy-button/2.4.0/buybutton.min.js"></script>
<script type="text/javascript">
(function () {
var scriptURL = 'https://sdks.shopifycdn.com/buy-button/latest/buy-button-storefront.min.js';
if (window.ShopifyBuy) {
if (window.ShopifyBuy.UI) {
ShopifyBuyInit();
} else {
loadScript();
}
} else {
loadScript();
}
function loadScript() {
var script = document.createElement('script');
script.async = true;
script.src = scriptURL;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(script);
script.onload = ShopifyBuyInit;
}
function ShopifyBuyInit() {
var client = ShopifyBuy.buildClient({
domain: 'xxxxx.myshopify.com',
storefrontAccessToken: 'shpat_xxxxxxxxxxxxxxxxx',
appId: '15'
});
ShopifyBuy.UI.onReady(client).then(function (ui) {
ui.createComponent('product', {
id: <?= $productID ?>,
node: document.getElementById('product-component-<?= $productID ?>'),
moneyFormat: '%24%24%24%7B%7Bamount%7D%7D',
options: {
"product": {
"variantId": "all",
"contents": {
"variantTitle": false,
"description": false,
"buttonWithQuantity": false,
"quantity": false
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "calc(25% - 20px)",
"margin-left": "20px",
"margin-bottom": "50px"
}
}
}
},
"cart": {
"contents": {
"button": true
},
"styles": {
"footer": {
"background-color": "#ffffff"
}
}
},
"modalProduct": {
"contents": {
"variantTitle": false,
"buttonWithQuantity": false,
"quantity": false
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "100%",
"margin-left": "0px",
"margin-bottom": "0px"
}
}
}
},
"productSet": {
"styles": {
"products": {
"@media (min-width: 601px)": {
"margin-left": "-20px"
}
}
}
}
}
});
});
}
})();
</script>