お世話になります。
カートページに特定の商品をカートに追加するボタンを作成しました。
バリエーションを選択後購入ボタンをクリックした際、サイドバーを表示せず、カートページを更新し、カートに特定商品を追加できる様な使用にしたいと考えています。
JSの知識不足により、質問させていただきました。
【状況】
無料テーマ(Down)を使用し、コード編集によりカートページに特定商品(バリエーションは2つ)をカートに追加できる項目を儲けた。
(上記理由)
テーマのカスタマイズによる、特定商品のだと、カートに追加するボタンのテキストが「カートに追加」で固定されてしまうため、独自でボタンを作成した。
使用テーマ:Down(バージョン9.0.0)
【やりたいこと】
・購入ボタンをクリックした際に選択したバリエーションの商品がカートに追加される状態を実現したい。
・カートに商品が追加される際、サイドバーのカートに追加ではなく、カートページを更新する形にしたい。
下記コードをもとに上記項目踏まえ、編集したいと考えています。
<div id='product-component-1684763358295'></div>
<script type="text/javascript">
/*<![CDATA[*/
(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: 'fitu-onaoshi.myshopify.com',
storefrontAccessToken: '0ba235b21d94f1dc61e8aea8e4694ee8',
});
ShopifyBuy.UI.onReady(client).then(function (ui) {
ui.createComponent('product', {
id: '8055638688003',
node: document.getElementById('product-component-1684763358295'),
moneyFormat: '%C2%A5%7B%7Bamount_no_decimals%7D%7D',
options: {
"product": {
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "calc(25% - 20px)",
"margin-left": "20px",
"margin-bottom": "50px"
}
},
"button": {
"font-family": "Lato, sans-serif",
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px",
"color": "#000000",
":hover": {
"color": "#000000",
"background-color": "#cbcbcb"
},
"background-color": "#e2e2e2",
":focus": {
"background-color": "#cbcbcb"
},
"border-radius": "5px",
"padding-left": "33px",
"padding-right": "33px"
},
"quantityInput": {
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px"
},
"price": {
"color": "#ffffff"
},
"compareAt": {
"color": "#ffffff"
},
"unitPrice": {
"color": "#ffffff"
}
},
"text": {
"button": "選択する"
},
"googleFonts": [
"Lato"
]
},
"productSet": {
"styles": {
"products": {
"@media (min-width: 601px)": {
"margin-left": "-20px"
}
}
}
},
"modalProduct": {
"contents": {
"img": false,
"imgWithCarousel": true,
"button": false,
"buttonWithQuantity": true
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "100%",
"margin-left": "0px",
"margin-bottom": "0px"
}
},
"button": {
"font-family": "Lato, sans-serif",
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px",
"color": "#000000",
":hover": {
"color": "#000000",
"background-color": "#cbcbcb"
},
"background-color": "#e2e2e2",
":focus": {
"background-color": "#cbcbcb"
},
"border-radius": "5px",
"padding-left": "33px",
"padding-right": "33px"
},
"quantityInput": {
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px"
},
"price": {
"font-family": "Helvetica Neue, sans-serif",
"font-weight": "normal",
"font-size": "18px",
"color": "#4c4c4c"
},
"compareAt": {
"font-family": "Helvetica Neue, sans-serif",
"font-weight": "normal",
"font-size": "15.299999999999999px",
"color": "#4c4c4c"
},
"unitPrice": {
"font-family": "Helvetica Neue, sans-serif",
"font-weight": "normal",
"font-size": "15.299999999999999px",
"color": "#4c4c4c"
}
},
"googleFonts": [
"Lato"
],
"text": {
"button": "Add to cart"
}
},
"option": {},
"cart": {
"styles": {
"button": {
"font-family": "Lato, sans-serif",
"font-size": "14px",
"padding-top": "15px",
"padding-bottom": "15px",
"color": "#000000",
":hover": {
"color": "#000000",
"background-color": "#cbcbcb"
},
"background-color": "#e2e2e2",
":focus": {
"background-color": "#cbcbcb"
},
"border-radius": "5px"
}
},
"text": {
"total": "小計",
"empty": "カートを空にする",
"notice": "",
"button": "購入する"
},
"popup": false,
"googleFonts": [
"Lato"
]
},
"toggle": {
"styles": {
"toggle": {
"font-family": "Lato, sans-serif",
"background-color": "#e2e2e2",
":hover": {
"background-color": "#cbcbcb"
},
":focus": {
"background-color": "#cbcbcb"
}
},
"count": {
"font-size": "14px",
"color": "#000000",
":hover": {
"color": "#000000"
}
},
"iconPath": {
"fill": "#000000"
}
},
"googleFonts": [
"Lato"
]
}
},
});
});
}
})();
/*]]>*/
</script>