From 10e8ed8be49727c4d1f12dd85b1ac8f5a6072a15 Mon Sep 17 00:00:00 2001 From: merino Date: Mon, 2 Dec 2024 12:42:06 +0100 Subject: [PATCH] Update checkout script --- scripts/checkout.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/checkout.js b/scripts/checkout.js index f0f323c68..5e84b8b51 100644 --- a/scripts/checkout.js +++ b/scripts/checkout.js @@ -22,14 +22,18 @@ export function getCartAddress(checkoutData, type) { company: address?.company, countryCode: address.country?.value, customAttributes: address.customAttributes, + fax: address.fax, firstName: address.firstName, lastName: address.lastName, + middleName: address.middleName, postcode: address.postCode, + prefix: address.prefix, region: { regionCode: address.region?.code, regionId: address.region?.id, }, street: address.street, + suffix: address.suffix, telephone: address.telephone, vatId: address.vatId, }; @@ -59,16 +63,16 @@ const transformAddressFormValues = (data) => { company: data?.company, countryCode: data.countryCode, customAttributes, - // TODO fax + fax: data.fax, firstName: data.firstName, lastName: data.lastName, - // TODO middleName + middleName: data.middleName, postcode: data.postcode, - // TODO prefix + prefix: data.prefix, region: data?.region?.regionCode, regionId: data?.region?.regionId, street: data.street, - // TODO suffix + suffix: data.suffix, telephone: data.telephone, vatId: data.vatId, saveInAddressBook: data.saveAddressBook, @@ -76,12 +80,17 @@ const transformAddressFormValues = (data) => { }; }; +let ongoingSetAddressCalls = 0; export function setAddressOnCart({ api, debounceMs = 0, placeOrderBtn = null }) { const debouncedApi = debounce((address) => { + ongoingSetAddressCalls += 1; api(address) .catch(console.error) .finally(() => { - placeOrderBtn?.setProps((prev) => ({ ...prev, disabled: false })); + ongoingSetAddressCalls -= 1; + if (ongoingSetAddressCalls === 0) { + placeOrderBtn?.setProps((prev) => ({ ...prev, disabled: false })); + } }); }, debounceMs);