Skip to content

Commit 3b66dd4

Browse files
committed
Price of product in cart affected by catalog price rule does not change when rule is adjusted by the staging update
1 parent 1053adc commit 3b66dd4

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,32 @@ define([
1313
* Compare central cart subtotal with summary subtotal and click Update once if mismatched.
1414
*/
1515
return function initEnsureSubtotalSync(config, element) {
16-
var $root = $(element || document);
17-
var clicked = false;
16+
const $root = $(element || document);
17+
let clicked = false;
1818

1919
function parsePrice(text) {
2020
if (!text) {
2121
return NaN;
2222
}
2323
// Remove non-numeric except . , - then normalize
24-
var cleaned = ('' + text).replace(/[^0-9,.-]/g, '');
24+
let cleaned = ('' + text).replace(/[^0-9,.-]/g, '');
2525
// If both , and . exist, assume , is thousands
2626
if (cleaned.indexOf(',') > -1 && cleaned.indexOf('.') > -1) {
2727
cleaned = cleaned.replace(/,/g, '');
2828
} else if (cleaned.indexOf(',') > -1 && cleaned.indexOf('.') === -1) {
2929
// European format: swap , to .
3030
cleaned = cleaned.replace(/,/g, '.');
3131
}
32-
var n = parseFloat(cleaned);
32+
const n = parseFloat(cleaned);
3333
return isNaN(n) ? NaN : Math.round(n * 100) / 100;
3434
}
3535

3636
function getCentralSubtotal() {
3737
// Sum of row totals on the table
38-
var sum = 0;
38+
let sum = 0;
3939
$root.find('#shopping-cart-table .col.subtotal .cart-price').each(function () {
40-
var text = $(this).text();
41-
var val = parsePrice(text);
40+
const text = $(this).text();
41+
const val = parsePrice(text);
4242
if (!isNaN(val)) {
4343
sum += val;
4444
}
@@ -48,18 +48,18 @@ define([
4848

4949
function getSummarySubtotal() {
5050
// Summary subtotal in cart totals knockout template
51-
var text = $('#cart-totals .totals.sub .amount .price').first().text();
51+
const text = $('#cart-totals .totals.sub .amount .price').first().text();
5252
return parsePrice(text);
5353
}
5454

5555
function trySync() {
5656
if (clicked) {
5757
return;
5858
}
59-
var central = getCentralSubtotal();
60-
var summary = getSummarySubtotal();
59+
const central = getCentralSubtotal();
60+
const summary = getSummarySubtotal();
6161
if (!isNaN(central) && !isNaN(summary) && central !== summary) {
62-
var $updateBtn = $root.find('.cart.main.actions button.action.update');
62+
const $updateBtn = $root.find('.cart.main.actions button.action.update');
6363
if ($updateBtn.length) {
6464
clicked = true;
6565
$updateBtn.trigger('click');
@@ -72,9 +72,9 @@ define([
7272
trySync();
7373
setTimeout(trySync, 300);
7474
// Observe changes in totals area to re-check once
75-
var totals = document.getElementById('cart-totals');
75+
const totals = document.getElementById('cart-totals');
7676
if (totals && typeof MutationObserver !== 'undefined') {
77-
var obs = new MutationObserver(function () {
77+
const obs = new MutationObserver(function () {
7878
trySync();
7979
if (clicked) {
8080
obs.disconnect();

0 commit comments

Comments
 (0)