Skip to content

Commit 06ea950

Browse files
committed
AC-16096: [Cart] Shopping cart page is not loading when Fixed product Tax is enable
fix: prevent cart refresh loop with AJAX-based price sync Result: One-time seamless cart update per session with proper UX feedback, no jarring page reloads, no infinite loops.
1 parent 0dce8c8 commit 06ea950

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

app/code/Magento/Checkout/view/frontend/web/js/cart/ensure-subtotal-sync.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ define([
1515
return function initEnsureSubtotalSync(config, element)
1616
{
1717
const $root = $(element || document);
18-
let clicked = false;
18+
19+
// Check if already synced on the body element (persists across form replacements)
20+
if ($('body').data('cart-synced')) {
21+
return;
22+
}
1923

2024
function parsePrice(text)
2125
{
@@ -70,19 +74,34 @@ define([
7074
return;
7175
}
7276

73-
if (clicked) {
74-
return;
75-
}
76-
7777
const central = getCentralSubtotal(), summary = getSummarySubtotal();
7878

7979
if (!isNaN(central) && !isNaN(summary) && central !== summary) {
80-
const $updateBtn = $root.find('.cart.main.actions button.action.update');
81-
82-
if ($updateBtn.length) {
83-
clicked = true;
84-
$updateBtn.trigger('click');
85-
}
80+
// Mark as synced immediately to prevent multiple calls
81+
$('body').data('cart-synced', true);
82+
83+
// Reload cart content via AJAX
84+
$('body').trigger('processStart');
85+
$.ajax({
86+
url: window.location.href,
87+
type: 'GET',
88+
data: { ajax: 1 },
89+
success: function(response) {
90+
// Extract and replace cart form
91+
const newContent = $(response).find('#form-validate');
92+
$('#form-validate').replaceWith(newContent);
93+
94+
// Reinitialize widgets on new content
95+
$('#form-validate').trigger('contentUpdated');
96+
},
97+
error: function() {
98+
$('body').trigger('processStop');
99+
$('body').data('cart-synced', false);
100+
},
101+
complete: function() {
102+
$('body').trigger('processStop');
103+
}
104+
});
86105
}
87106
}
88107

@@ -98,7 +117,7 @@ define([
98117
const obs = new MutationObserver(function () {
99118
trySync();
100119

101-
if (clicked) {
120+
if ($('body').data('cart-synced')) {
102121
obs.disconnect();
103122
}
104123
});

0 commit comments

Comments
 (0)