From 8322cc01319b5184192dbb84eba9e41de2017133 Mon Sep 17 00:00:00 2001 From: Roy Duineveld Date: Thu, 27 Oct 2022 14:46:44 +0200 Subject: [PATCH] Fixed empty customer address error in the checkout --- resources/js/components/Checkout/Checkout.vue | 6 +++++ .../User/mixins/InteractWithUser.js | 25 ++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/resources/js/components/Checkout/Checkout.vue b/resources/js/components/Checkout/Checkout.vue index 91654954c..9938e51b0 100644 --- a/resources/js/components/Checkout/Checkout.vue +++ b/resources/js/components/Checkout/Checkout.vue @@ -314,12 +314,18 @@ } }, watch: { + 'checkout.shipping_address.customer_address_id': function (customerAddressId) { + this.setCustomerAddressByAddressId('shipping', customerAddressId) + }, 'checkout.shipping_address': { deep: true, handler: function() { this.storeCredentials('shipping') } }, + 'checkout.billing_address.customer_address_id': function (customerAddressId) { + this.setCustomerAddressByAddressId('billing', customerAddressId) + }, 'checkout.billing_address': { deep: true, handler: function() { diff --git a/resources/js/components/User/mixins/InteractWithUser.js b/resources/js/components/User/mixins/InteractWithUser.js index ba8ea9ccd..2b41cffe0 100644 --- a/resources/js/components/User/mixins/InteractWithUser.js +++ b/resources/js/components/User/mixins/InteractWithUser.js @@ -83,20 +83,21 @@ export default { setCheckoutCredentialsFromDefaultUserAddresses() { if (this.$root && this.$root.user) { - if (this.$root.user.default_shipping) { - let address = this.$root.user.addresses.find((address) => address.id == this.$root.user.default_shipping) - this.$root.checkout.shipping_address = Object.assign({ - customer_address_id: address.id - }, address) - } + this.setCustomerAddressByAddressId('shipping', this.$root.user.default_shipping) + this.setCustomerAddressByAddressId('billing', this.$root.user.default_billing) + } + }, - if (this.$root.user.default_billing) { - let address = this.$root.user.addresses.find((address) => address.id == this.$root.user.default_billing) - this.$root.checkout.billing_address = Object.assign({ - customer_address_id: address.id - }, address) - } + setCustomerAddressByAddressId(type, id) { + if (!id) { + return } + + let address = this.$root.user.addresses.find((address) => address.id == id) + + this.$root.checkout[type + '_address'] = Object.assign({ + customer_address_id: address.id + }, address) }, },