Skip to content

Commit

Permalink
fix(storefront): STRF-12475 Use fetch when updating variants in cart
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanarldt committed Dec 16, 2024
1 parent b25b270 commit 9658556
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions assets/js/theme/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9658556

Please sign in to comment.