Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helper that removes non default addresses #3938

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions core/modules/user/components/UserAccount.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -148,6 +149,7 @@ export const UserAccount = {
newPassword: this.password
})
}
removeNonDefaultAddress(updatedProfile)
this.exitSection(null, updatedProfile)
},
exitSection (event, updatedProfile) {
Expand Down
2 changes: 2 additions & 0 deletions core/modules/user/components/UserShippingDetails.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -109,6 +110,7 @@ export const UserShippingDetails = {
})
}
}
removeNonDefaultAddress(updatedShippingDetails)
this.exitSection(null, updatedShippingDetails)
},
exitSection (event, updatedShippingDetails) {
Expand Down
5 changes: 5 additions & 0 deletions core/modules/user/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import removeNonDefaultAddress from './removeNonDefaultAddress'

export {
removeNonDefaultAddress
}
9 changes: 9 additions & 0 deletions core/modules/user/helpers/removeNonDefaultAddress.ts
Original file line number Diff line number Diff line change
@@ -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