diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ce1136336..48848b75f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed Breadcrumb filters - apply to second category fetch - @grimasod (#3887) - Fixed `config.storeViews.commonCache` being ignored - @grimasod (#3895) - Fixed static pages, password notification, offline mode #3902 - @andrzejewsky (#3902) +- Fixed edit shipping address in my account - @gibkigonzo (#3921) - Fetch cms_block content in serverPrefetch method - @gibkigonzo (#3910) ### Changed / Improved diff --git a/core/modules/user/components/UserShippingDetails.ts b/core/modules/user/components/UserShippingDetails.ts index bba3b74a4e..d9aacfc805 100644 --- a/core/modules/user/components/UserShippingDetails.ts +++ b/core/modules/user/components/UserShippingDetails.ts @@ -89,21 +89,24 @@ export const UserShippingDetails = { ...(this.shippingDetails.region ? { region: { region: this.shippingDetails.region } } : {}), country_id: this.shippingDetails.country, postcode: this.shippingDetails.postcode, - ...(this.shippingDetails.phone ? { telephone: this.shippingDetails.phone } : {}), - default_shipping: true + ...(this.shippingDetails.phone ? { telephone: this.shippingDetails.phone } : {}) } if (this.currentUser.hasOwnProperty('default_shipping')) { - let i - for (i = 0; i < this.currentUser.addresses.length; i++) { - if (toString(this.currentUser.addresses[i].id) === toString(this.currentUser.default_shipping)) { - updatedShippingDetails.addresses[i] = updatedShippingDetailsAddress; - } - } - if (this.currentUser.addresses.length === 0 || i === this.currentUser.addresses.length) { + if (this.currentUser.addresses.length === 0) { updatedShippingDetails = null + } else { + updatedShippingDetails.addresses = updatedShippingDetails.addresses.map((address) => + toString(address.id) === toString(this.currentUser.default_shipping) + ? {...address, ...updatedShippingDetailsAddress} // update default address if already exist + : address + ) } } else { - updatedShippingDetails.addresses.push(updatedShippingDetailsAddress) + // create default address + updatedShippingDetails.addresses.push({ + ...updatedShippingDetailsAddress, + default_shipping: true + }) } } this.exitSection(null, updatedShippingDetails)