MS-311/feat(checkout): reactive cart sync, backend shipping persistence & remove page-reload pattern
Summary
This MR removes all window.location.reload() calls from the checkout flow and
replaces them with a fully reactive, state-driven architecture. It also introduces
server-side shipping price persistence to support backend-computed shipping discounts.
Problem
Every discount action in the checkout (applying or removing a promo code, voucher, or gift card) triggered a full page reload with a 1.2 s delay. This caused the billing and shipping address forms to reset, produced visible flickering, and made it impossible to reflect server-side shipping discounts or handle edge cases like a cart total dropping to zero or a previously selected shipping method becoming unavailable after a promo.
What Changed
Discount actions no longer reload the page. Applying or removing a promo code, voucher, or gift card now updates the cart totals, discount lines, and shipping methods instantly in place. The address form fields are preserved throughout.
Shipping costs are now synced with the backend. When a shipping method is selected, its price is persisted server-side. If a promo code that discounts shipping is applied, the reduced price is immediately reflected in the order summary with the original price shown struck through. Voucher and gift card shipping discount support is pending backend implementation.
Shipping methods re-evaluate automatically after a cart change. When a discount is applied or removed, the available shipping methods are re-fetched. If the previously selected method is no longer available, the user is notified and the first available method is selected automatically.
Payment method survives a zero-total transition. If a discount makes the order total drop to zero (hiding the payment section) and is then removed, the payment method the user had previously chosen is automatically restored. If that method is no longer active, the first available one is selected with a warning.
Testing Checklist
-
Apply a promo code → totals update instantly, shipping re-evaluated, no reload -
Remove a promo code → totals revert, payment method restored if total was 0 -
Apply a promo that discounts shipping → original price shown struck through -
Apply a voucher or gift card → cart reflects the discount without reload -
Remove a voucher or gift card → cart reverts without reload -
Select a shipping method → price persisted to backend, discount applied if any -
Switch delivery country → shipping methods re-filtered correctly -
Cart change makes selected shipping method unavailable → warning + auto-fallback -
Full discount brings total to 0 → payment section hidden, order button shown -
Remove that discount → payment method restored from previous selection
⚠ ️ Voucher and gift card shipping discount scenarios are not yet testable — backend support is pending.
Breaking Changes
None for the frontend. The Cart type additions are backward-compatible.
⚠ ️ Backend dependency: requiresPUT /api/cart/:clientId/shipping?shippingPrice=<value>returning the updatedCartobject withshippingPriceAfterDiscount.