Last active
May 10, 2021 18:00
-
-
Save S-Maxime/7cb36116177ac0fcd5e1ed0e5d8f74fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| computed: { | |
| userAddresses () { | |
| return rootStore.state.user.current ? rootStore.state.user.current.addresses : [] | |
| }, | |
| addresses () { | |
| return this.userAddresses.map((address) => { | |
| if (address.hasOwnProperty('custom_attributes') && address.custom_attributes.length > 0) { | |
| for (let opt of address.custom_attributes) { | |
| address[opt.attribute_code] = opt.value; | |
| } | |
| delete address.custom_attributes | |
| } | |
| return address | |
| }) | |
| }, | |
| /** | |
| * Shipping Address | |
| * @returns {Address} | |
| */ | |
| shippingAddress () { | |
| return this.addresses.find(item => item.default_shipping) | |
| }, | |
| /** | |
| * Billing Address | |
| * @returns {Address} | |
| */ | |
| billingAddress () { | |
| return this.addresses.find(item => item.default_billing) | |
| }, | |
| /** | |
| * Additional Addresses | |
| * @returns {Address[]} | |
| */ | |
| additionalAddresses () { | |
| return this.addresses.filter(item => !item.default_shipping && !item.default_billing) | |
| } | |
| }, | |
| beforeMount () { | |
| if (!isServer) { | |
| this.$bus.$on('addressChanged', (addresses) => { | |
| /** | |
| addresses has the updated value and he's completely OK BUT | |
| **/ | |
| this.addresses = [] // this doens't work and don't update the computed | |
| this.addresses = addresses // this doesn't work and don't update the computed | |
| console.log(addresses) Good :) | |
| console.log(this.addresses) Never good | |
| }) | |
| } | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment