Skip to content

Commit c44aaaa

Browse files
committed
#68 - save customer data if user logged in
1 parent 5bfd5fe commit c44aaaa

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

view/frontend/web/js/App.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export default {
2929
TotalsData,
3030
ProductsList,
3131
ProgressBar
32+
},
33+
created () {
34+
if (window.config.isCustomerLoggedIn) {
35+
this.$store.dispatch('getCustomerData')
36+
}
3237
}
3338
}
3439
</script>

view/frontend/web/js/components/CustomerEmailField.vue

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div>
33
<BaseInput
4-
v-model.trim="$v.customer.email.$model"
5-
:validation="$v.customer.email"
4+
v-model.trim="$v.email.$model"
5+
:validation="$v.email"
66
label="Email"
77
name="email"
88
type="email"
@@ -27,27 +27,26 @@ export default {
2727
},
2828
data () {
2929
return {
30-
customer: {
31-
email: '',
32-
emailAvailable: false
33-
}
30+
email: '',
31+
emailAvailable: false
3432
}
3533
},
3634
validations: {
37-
customer: {
38-
email: {
39-
required,
40-
email
41-
}
35+
email: {
36+
required,
37+
email
4238
}
4339
},
4440
computed: {
41+
customerData () {
42+
return this.$store.state.customer
43+
},
4544
ready () {
46-
return !this.$v.customer.email.$invalid
45+
return !this.$v.email.$invalid
4746
},
4847
emailAvailabilityMessage () {
49-
if (this.customer.email !== '' && !this.$v.customer.email.$error) {
50-
if (this.customer.emailAvailable) {
48+
if (this.email !== '' && !this.$v.email.$error) {
49+
if (this.emailAvailable) {
5150
return `You can create an account after checkout.`
5251
} else {
5352
return `
@@ -65,21 +64,29 @@ export default {
6564
this.$emit('ready', val)
6665
}
6766
},
67+
created () {
68+
if (
69+
this.customerData !== null &&
70+
this.customerData.hasOwnProperty('email')
71+
) {
72+
this.email = this.customerData.email
73+
}
74+
},
6875
methods: {
6976
touch () {
70-
this.$v.customer.email.$touch()
77+
this.$v.email.$touch()
7178
},
7279
checkIsEmailAvailable () {
7380
const options = {
7481
method: 'POST',
7582
data: JSON.stringify({
76-
'customerEmail': this.customer.email
83+
'customerEmail': this.email
7784
}),
7885
url: 'customers/isEmailAvailable'
7986
}
8087
axios(options)
8188
.then(({data}) => {
82-
this.customer.emailAvailable = data
89+
this.emailAvailable = data
8390
})
8491
.catch(error => {
8592
console.error('Looks like there was a problem: \n', error)
@@ -88,7 +95,7 @@ export default {
8895
this.$store.commit('setItem', {
8996
item: 'customer',
9097
value: {
91-
email: this.customer.email
98+
email: this.email
9299
}
93100
})
94101
}

view/frontend/web/js/store/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default {
124124
})
125125
})
126126
},
127-
getCustomerAddresses ({ commit }) {
127+
getCustomerData ({ commit }) {
128128
axios.get('customers/me')
129129
.then(response => {
130130
if (response.data) {

view/frontend/web/js/store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const store = new Vuex.Store({
1212
state: {
1313
config: window.config,
1414
baseUrl: window.baseUrl,
15-
customer: window.config.customerData,
15+
customer: null,
1616
regions,
1717
step: 'shipping',
1818
orderId: null,

0 commit comments

Comments
 (0)