Skip to content

Commit 232e5c0

Browse files
MAGETWO-94406: [2.3.0] "Directory Data" and "Cart" sections are loaded twice after user logged in
- Updated customer data reload
1 parent 419fd4b commit 232e5c0

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

app/code/Magento/Checkout/view/frontend/web/js/view/minicart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ define([
101101
self.isLoading(true);
102102
});
103103

104-
if (cartData()['website_id'] !== window.checkout.websiteId) {
104+
if ((cartData()['website_id'] !== window.checkout.websiteId) && !customerData.get('is-loading')) {
105105
customerData.reload(['cart'], false);
106106
}
107107

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,16 @@ define([
8787
} : [];
8888
parameters['update_section_id'] = updateSectionId;
8989

90-
return $.getJSON(options.sectionLoadUrl, parameters).fail(function (jqXHR) {
91-
throw new Error(jqXHR);
92-
});
90+
return $.getJSON(options.sectionLoadUrl, parameters)
91+
.done(
92+
function () {
93+
if (_.isEmpty(sectionNames)) {
94+
customerData.set('is_loading', false);
95+
}
96+
}
97+
).fail(function (jqXHR) {
98+
throw new Error(jqXHR);
99+
});
93100
}
94101
};
95102

@@ -199,7 +206,8 @@ define([
199206
privateContent = $.cookieStorage.get(privateContentVersion),
200207
localPrivateContent = $.localStorage.get(privateContentVersion),
201208
needVersion = 'need_version',
202-
expiredSectionNames = this.getExpiredSectionNames();
209+
expiredSectionNames = this.getExpiredSectionNames(),
210+
isLoading = false;
203211

204212
if (privateContent &&
205213
!$.cookieStorage.isSet(privateContentVersion) &&
@@ -208,13 +216,15 @@ define([
208216
$.cookieStorage.set(privateContentVersion, needVersion);
209217
$.localStorage.set(privateContentVersion, needVersion);
210218
this.reload([], false);
219+
this.set('is_loading', true);
211220
} else if (localPrivateContent !== privateContent) {
212221
if (!$.cookieStorage.isSet(privateContentVersion)) {
213222
privateContent = needVersion;
214223
$.cookieStorage.set(privateContentVersion, privateContent);
215224
}
216225
$.localStorage.set(privateContentVersion, privateContent);
217226
this.reload([], false);
227+
this.set('is_loading', true);
218228
} else if (expiredSectionNames.length > 0) {
219229
_.each(dataProvider.getFromStorage(storage.keys()), function (sectionData, sectionName) {
220230
buffer.notify(sectionName, sectionData);
@@ -232,8 +242,9 @@ define([
232242

233243
if (!_.isEmpty(privateContent)) {
234244
countryData = this.get('directory-data');
245+
isLoading = this.get('is_loading');
235246

236-
if (_.isEmpty(countryData())) {
247+
if (_.isEmpty(countryData()) && !isLoading) {
237248
customerData.reload(['directory-data'], false);
238249
}
239250
}
@@ -328,7 +339,6 @@ define([
328339
*/
329340
reload: function (sectionNames, updateSectionId) {
330341
return dataProvider.getFromServer(sectionNames, updateSectionId).done(function (sections) {
331-
$(document).trigger('customer-data-reload', [sectionNames]);
332342
buffer.update(sections);
333343
});
334344
},

0 commit comments

Comments
 (0)