diff --git a/CHANGELOG.md b/CHANGELOG.md index b62eefb461..7d554e0266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -93,6 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - check max quantity in microcart - @gibkigonzo (#3314) - Add unit tests for `core/modules/newsletter` - @psmyrek (#3464) - Add unit test for `core/modules/wishlist` - @psmyrek (#3471) +- Add helper that removes non default addresses - @gibkigonzo (#3921) ### Changed / Improved - Use `encodeURIComponent` to encode get parameters in `multimatch.js` - @adityasharma7 (#3736) diff --git a/core/modules/user/components/UserAccount.ts b/core/modules/user/components/UserAccount.ts index b62cad6310..dbcda25db8 100644 --- a/core/modules/user/components/UserAccount.ts +++ b/core/modules/user/components/UserAccount.ts @@ -1,4 +1,5 @@ import toString from 'lodash-es/toString' +import { removeNonDefaultAddress } from '../helpers' const Countries = require('@vue-storefront/core/i18n/resource/countries.json') export const UserAccount = { @@ -148,6 +149,7 @@ export const UserAccount = { newPassword: this.password }) } + removeNonDefaultAddress(updatedProfile) this.exitSection(null, updatedProfile) }, exitSection (event, updatedProfile) { diff --git a/core/modules/user/components/UserShippingDetails.ts b/core/modules/user/components/UserShippingDetails.ts index d9aacfc805..5e5bbc985c 100644 --- a/core/modules/user/components/UserShippingDetails.ts +++ b/core/modules/user/components/UserShippingDetails.ts @@ -1,4 +1,5 @@ import toString from 'lodash-es/toString' +import { removeNonDefaultAddress } from '../helpers' const Countries = require('@vue-storefront/i18n/resource/countries.json') export const UserShippingDetails = { @@ -109,6 +110,7 @@ export const UserShippingDetails = { }) } } + removeNonDefaultAddress(updatedShippingDetails) this.exitSection(null, updatedShippingDetails) }, exitSection (event, updatedShippingDetails) { diff --git a/core/modules/user/helpers/index.ts b/core/modules/user/helpers/index.ts new file mode 100644 index 0000000000..dc2968da6b --- /dev/null +++ b/core/modules/user/helpers/index.ts @@ -0,0 +1,5 @@ +import removeNonDefaultAddress from './removeNonDefaultAddress' + +export { + removeNonDefaultAddress +} diff --git a/core/modules/user/helpers/removeNonDefaultAddress.ts b/core/modules/user/helpers/removeNonDefaultAddress.ts new file mode 100644 index 0000000000..50eee0c12c --- /dev/null +++ b/core/modules/user/helpers/removeNonDefaultAddress.ts @@ -0,0 +1,9 @@ +/** + * we can have only two addresses: 'shipping' or 'billing' + */ +const removeNonDefaultAddress = (updatedProfile) => { + if (!(updatedProfile && updatedProfile.addresses)) return + updatedProfile.addresses = updatedProfile.addresses.filter((address) => address.default_shipping || address.default_billing) +} + +export default removeNonDefaultAddress