Skip to content

Commit c442f76

Browse files
Andrii Beziazychnyiandrewbess
authored andcommitted
#13765 Excess requests 'customer data' on checkout cart page were fixed:
- Excess request for 'directory-data' was fixed; - Excess requests for 'cart' were fixed.
1 parent a60b822 commit c442f76

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/totals.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ define([
1414
'use strict';
1515

1616
var quoteItems = ko.observable(quote.totals().items),
17-
cartData = customerData.get('cart'),
18-
quoteSubtotal = parseFloat(quote.totals().subtotal),
19-
subtotalAmount = parseFloat(cartData().subtotalAmount);
17+
cartData = customerData.get('cart');
2018

2119
quote.totals.subscribe(function (newValue) {
2220
quoteItems(newValue.items);
2321
});
2422

25-
if (quoteSubtotal !== subtotalAmount) {
26-
customerData.reload(['cart'], false);
27-
}
23+
cartData.subscribe(function () {
24+
var quoteSubtotal = parseFloat(quote.totals().subtotal),
25+
subtotalAmount = parseFloat(cartData().subtotalAmount);
26+
if (quoteSubtotal !== subtotalAmount) {
27+
customerData.reload(['cart'], false);
28+
}
29+
}, this);
2830

2931
return {
3032
totals: quote.totals,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,16 @@ define([
9494
this.isLoading(addToCartCalls > 0);
9595
sidebarInitialized = false;
9696
this.update(updatedCart);
97+
if (cartData()['website_id'] !== window.checkout.websiteId) {
98+
customerData.reload(['cart'], false);
99+
}
97100
initSidebar();
98101
}, this);
99102
$('[data-block="minicart"]').on('contentLoading', function () {
100103
addToCartCalls++;
101104
self.isLoading(true);
102105
});
103106

104-
if (cartData()['website_id'] !== window.checkout.websiteId) {
105-
customerData.reload(['cart'], false);
106-
}
107-
108107
return this._super();
109108
},
110109
isLoading: ko.observable(false),

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,11 @@ define([
232232
if (!_.isEmpty(privateContent)) {
233233
countryData = this.get('directory-data');
234234

235-
if (_.isEmpty(countryData())) {
236-
customerData.reload(['directory-data'], false);
237-
}
235+
countryData.subscribe(function () {
236+
if (_.isEmpty(countryData())) {
237+
customerData.reload(['directory-data'], false);
238+
}
239+
}, this);
238240
}
239241
},
240242

0 commit comments

Comments
 (0)