@@ -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 {
@@ -44,7 +48,7 @@ define([
4448 // Sum of row totals on the table
4549 let sum = 0 ;
4650
47- $root . find ( '#shopping-cart-table .col.subtotal .cart-price' ) . each ( function ( ) {
51+ $root . find ( '#shopping-cart-table .col.subtotal .price-excluding-tax . cart-price' ) . each ( function ( ) {
4852 const text = $ ( this ) . text ( ) , val = parsePrice ( text ) ;
4953
5054 if ( ! isNaN ( val ) ) {
@@ -70,19 +74,35 @@ 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+
93+ // Replace the form with the new content
94+ $ ( '#form-validate' ) . replaceWith ( newContent ) ;
95+ // Reinitialize widgets on new content
96+ $ ( '#form-validate' ) . trigger ( 'contentUpdated' ) ;
97+ } ,
98+ error : function ( ) {
99+ $ ( 'body' ) . trigger ( 'processStop' ) ;
100+ $ ( 'body' ) . data ( 'cart-synced' , false ) ;
101+ } ,
102+ complete : function ( ) {
103+ $ ( 'body' ) . trigger ( 'processStop' ) ;
104+ }
105+ } ) ;
86106 }
87107 }
88108
@@ -98,7 +118,7 @@ define([
98118 const obs = new MutationObserver ( function ( ) {
99119 trySync ( ) ;
100120
101- if ( clicked ) {
121+ if ( $ ( 'body' ) . data ( 'cart-synced' ) ) {
102122 obs . disconnect ( ) ;
103123 }
104124 } ) ;
0 commit comments