Liquid、JavaScriptなどに関する質問
https://shopify.dev/docs/api/ajax/reference/cart#bundled-section-rendering
↑を参考にした
let formData = { 'items': [...this.items], 'sections':['cart-notification-product', 'cart-notification-button', 'cart-icon-bubble'], 'sections_url': window.location.pathname }; fetch(window.Shopify.routes.root + 'cart/add.js', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }) .then(response => { console.log( response ); }) .catch((error) => { console.error('Error:', error); });
responceにsectionsが含まれて欲しいのですが返却値にありません。。
■返却されたデータ
■希望するレスポンス内容
{
attributes: {},
cart_level_discount_applications: [],
currency: "CAD",
item_count: 1,
items: [{…}],
items_subtotal_price: 100100,
note: null,
original_total_price: 100100,
requires_shipping: true,
sections: {
cart-items: "<div id=\"shopify-section-template--14199693705272_…9930913703934\" defer=\"defer\"></script>\n\n\n\n\n</div>",
cart-icon-bubble: "<div id=\"shopify-section-cart-icon-bubble\" class=\"…ss=\"visually-hidden\">1 item</span>\n </div></div>",
cart-live-region-text: "<div id=\"shopify-section-cart-live-region-text\" cl…opify-section\">New subtotal: $1,001.00 CAD\n</div>",
cart-footer: "<div id=\"shopify-section-template--14199693705272_… </div>\n </div>\n </div>\n</div>\n\n\n\n\n\n\n</div>"
},
token: "9ee5d43a08fb9a779828e42a4b6aa09a",
total_discount: 0,
total_price: 100100,
total_weight: 1000,
}
何か足りない部分があるのでしょうか?
よろしくお願いいたします。
解決済! ベストソリューションを見る。
成功
確認されているのはfetchで返されるResponseオブジェクトの中身です。
期待されるレスポンス内容は、response.json() をした結果のことだと思われます。
成功
確認されているのはfetchで返されるResponseオブジェクトの中身です。
期待されるレスポンス内容は、response.json() をした結果のことだと思われます。
ご回答ありがとうございます!
response.json()
で確認することを失念しておりました!
修正し、期待したレスポンスを確認することができました!
いつもShopifyをご利用いただき、ありがとうございます。 Shopifyは、皆様の日本語での利用体験の向上に努めております。さらなる改善のために皆様のご意見をお寄せい...
By JasonH May 9, 2025Shopify アカデミーの学習パスと認定スキルバッジExpanding Your Shopify Business Internationallyを活用して、国際的にビジネ...
By Shopify Feb 7, 2025Shopify アカデミーの学習パスB2B on Shopify:立ち上げとカスタマイズで卸売販売に進出しましょう。これら3つの無料コースは、ShopifyストアでB2B機能...
By Shopify Jan 31, 2025