我創建了一個具有自由文本訂購功能的自定義頁面,并呼叫 customadd to cart API將專案添加到購物車。
添加專案后,我需要使用更新的數量更新購物車專案計數。我試著用
require([
'jquery',
'Magento_Checkout/js/action/get-totals'
], function ($, getTotalsAction) {
'use strict';
var deferred = $.Deferred();
getTotalsAction([], deferred);
});
但它拋出錯誤:Uncaught TypeError:無法讀取在quote.js:34處未定義的屬性'quoteData'
和
url-builder.js:12 未捕獲的型別錯誤:無法讀取 url-builder.js:12 處未定義的屬性“storeCode”
這里有什么遺漏嗎?
我提到了https://magento.stackexchange.com/questions/210517/error-javascript-define-magento2-window-checkout-quotedata-or-store-code-are-u,它沒有任何可行的解決方案。
uj5u.com熱心網友回復:
問題是 quoteData 存在于 window.checkoutConfig - 此資料將僅在結帳頁面上設定,您將不會在自定義頁面上加載許多必需的 js 模塊來正確設定此資料。
這可能是一個有用的閱讀:https : //www.yireo.com/blog/2017-08-20-do-not-depend-on-window-checkoutconfig
uj5u.com熱心網友回復:
我能夠使用以下代碼為我的場景實作這一點。它可能會幫助某人
require([
'Magento_Customer/js/customer-data'
], function (customerData) {
var sections = ['cart'];
customerData.invalidate(sections);
customerData.reload(sections, true);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366769.html
