Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions view/frontend/templates/bfcache/handler.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $script = <<<JS
}

init() {
this._customerDataInitialized = false;
this.refreshMiniCart();
this.reloadCustomerLoginPage();
this.actionAutoCloseMenu(this.options.autoCloseMenuMobile);
Expand Down Expand Up @@ -102,25 +103,17 @@ $script = <<<JS
}

/**
* Dispatch Magento event to refresh customer sections (minicart, etc.)
* Dispatch Magento event to refresh customer sections (minicart, wishlist, etc.)
*/
actionRefreshMiniCart() {
require([
'Magento_Customer/js/customer-data'
], function (customerData) {
customerData.reload(['cart'], true);
});
this.initCustomerData();
}

/**
* Close minicart & optionally close mobile menu
*/
actionAutoCloseMenu(autoCloseMenuMobile) {
require([
'Magento_Customer/js/customer-data'
], ((customerData) => {
customerData.reload(['messages'], true);

this.initCustomerData(() => {
const minicartCloseButton = document.querySelector(this.selectors.minicartCloseButton);
if (minicartCloseButton) {
minicartCloseButton.click();
Expand All @@ -129,9 +122,24 @@ $script = <<<JS
if (autoCloseMenuMobile) {
this.handleMenuClosure();
}
}).bind(this));
});
}

/**
* Init customer data if not already initialized
*/
initCustomerData(callback = null) {
require(['Magento_Customer/js/customer-data'], customerData => {
if (!this._customerDataInitialized) {
customerData.init();
this._customerDataInitialized = true;
}
if (callback && typeof callback === 'function') {
callback();
}
});
}

/**
* Handle closing of mobile menu
*/
Expand Down