| @@ -62,8 +62,10 @@ | ||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | setNotices(wrapper, data.notices || ''); |
| 65 | 65 | initWrapper(wrapper); |
| 66 | + | |
| 67 | + document.body.dispatchEvent(new Event('wc_fragments_refreshed')); | |
| 66 | 68 | }; |
| 67 | 69 | |
| 68 | 70 | const request = (wrapper, payload) => { |
| 69 | 71 | const ajaxUrl = wrapper.dataset.ajaxUrl; |
| @@ -74,8 +76,15 @@ | ||
| 74 | 76 | |
| 75 | 77 | const body = new URLSearchParams(); |
| 76 | 78 | body.append('action', 'ka_cart_update'); |
| 77 | 79 | body.append('nonce', nonce); |
| 80 | + // Empty-cart copy, so the block rendered after the last item is removed | |
| 81 | + // matches the one a full page load produces. | |
| 82 | + ['emptyTitle', 'emptyMessage', 'emptyPrimaryText', 'emptyPrimaryUrl', 'emptySecondaryText', 'emptySecondaryUrl'] | |
| 83 | + .forEach((prop) => { | |
| 84 | + const key = prop.replace(/[A-Z]/g, (c) => '_' + c.toLowerCase()); | |
| 85 | + body.append(key, wrapper.dataset[prop] || ''); | |
| 86 | + }); | |
| 78 | 87 | Object.entries(payload).forEach(([k, v]) => body.append(k, v)); |
| 79 | 88 | |
| 80 | 89 | wrapper.classList.add('loading'); |
| 81 | 90 | |
| @@ -104,8 +113,15 @@ | ||
| 104 | 113 | if (!form) return; |
| 105 | 114 | |
| 106 | 115 | form.addEventListener('submit', (e) => { |
| 107 | 116 | e.preventDefault(); |
| 117 | + const updates = [...form.querySelectorAll('input[name^="cart["][name$="[qty]"]')] | |
| 118 | + .map((input) => ({ key: getKeyFromInput(input), qty: input.value })) | |
| 119 | + .filter((item) => item.key); | |
| 120 | + updates.reduce( | |
| 121 | + (chain, item) => chain.then(() => request(wrapper, { op: 'qty', cart_item_key: item.key, qty: item.qty })), | |
| 122 | + Promise.resolve() | |
| 123 | + ); | |
| 108 | 124 | }); |
| 109 | 125 | |
| 110 | 126 | form.addEventListener('change', (e) => { |
| 111 | 127 | const target = e.target; |