Skip to content

Commit

Permalink
Fixed empty customer address error in the checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
royduin committed Oct 27, 2022
1 parent 603ad2c commit 8322cc0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions resources/js/components/Checkout/Checkout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
25 changes: 13 additions & 12 deletions resources/js/components/User/mixins/InteractWithUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},

Expand Down

0 comments on commit 8322cc0

Please sign in to comment.