From 965855608d255bfa0ab84608627a0ed4b7a8f5b1 Mon Sep 17 00:00:00 2001 From: jordanarldt Date: Mon, 16 Dec 2024 11:43:53 -0600 Subject: [PATCH] fix(storefront): STRF-12475 Use fetch when updating variants in cart --- assets/js/theme/cart.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/assets/js/theme/cart.js b/assets/js/theme/cart.js index b3cae98796..65fdeeb9b8 100644 --- a/assets/js/theme/cart.js +++ b/assets/js/theme/cart.js @@ -151,6 +151,28 @@ export default class Cart extends PageManager { this.$modal.one(ModalEvents.opened, optionChangeHandler); } + const modalForm = this.$modal.find('form'); + + // Create block scoped reference to this.refreshContent, so it can be accessed via onSubmit + const refreshContent = () => this.refreshContent(); + + async function onSubmit(event) { + event.preventDefault(); + const formData = new FormData(this); + const resp = await fetch('/cart.php', { + method: 'POST', + credentials: 'include', + body: formData, + }); + + if (resp.ok) { + modal.close(); + refreshContent(); + } + } + + modalForm.on('submit', onSubmit); + this.productDetails = new CartItemDetails(this.$modal, context); this.bindGiftWrappingForm();