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

[WIP] #68 - added customer addresses component #116

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions test/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ localVue.use(Vuex)

describe('App.test.js', () => {
let store
let actions
let mutations
let wrapper

beforeEach(() => {
actions = {
getCustomerData: jest.fn()
mutations = {
setItem: jest.fn()
}
store = new Vuex.Store({
actions
mutations
})

wrapper = shallowMount(App, {
computed: {
isCustomerLoggedIn: () => true
isCustomerLoggedIn: () => true,
customerData: () => null
},
store,
localVue
Expand Down
8 changes: 7 additions & 1 deletion view/frontend/web/js/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ export default {
computed: {
isCustomerLoggedIn () {
return this.$store.getters.isCustomerLoggedIn
},
customerData () {
return window.config.customerData
}
},
mounted () {
if (this.isCustomerLoggedIn) {
this.$store.dispatch('getCustomerData')
this.$store.commit('setItem', {
item: 'customer',
value: this.customerData
})
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions view/frontend/web/js/components/AddressData.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<template>
<address>
<address :class="{ active: address.default_billing }">
{{ address.firstname }} {{ address.lastname }}<br>
{{ address.street[0] }} {{ address.street[1] }}<br>
{{ address.city }}<br>
{{ address.postcode }}<br>
{{ address.region }}<br>
<template v-if="typeof address.region === 'object'">
{{ address.region.region }}<br>
</template>
<template v-else>
{{ address.region }}<br>
</template>
{{ address.country_id.label }}<br>
{{ address.telephone }}<br>
{{ address.company }}
Expand All @@ -21,3 +26,9 @@ export default {
}
}
</script>

<style scoped>
.active {
border: 1px solid #000;
}
</style>
35 changes: 35 additions & 0 deletions view/frontend/web/js/components/CustomerAddresses.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<div>
<AddressData
v-for="address in addresses"
:address="address"
:key="address.id"
class="address-item"
/>
</div>
</template>

<script>
import AddressData from './AddressData.vue'

export default {
components: {
AddressData
},
computed: {
addresses () {
if (this.$store.state.customer !== null) {
return this.$store.state.customer.addresses
}
}
}
}
</script>

<style>
.address-item {
padding: 10px;
margin-bottom: 10px;
border: 1px solid #c2c2c2;
}
</style>
14 changes: 13 additions & 1 deletion view/frontend/web/js/components/steps/TheShippingStep.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
ref="customerEmail"
@ready="isReady => customerEmailReadyToSubmit = isReady"
/>
<CustomerAddresses v-if="isCustomerLoggedIn"/>
<BaseButton
text="Add new address"
@click.native="addNewAddress()"
/>
<ShippingAddressForm
v-if="!isCustomerLoggedIn || newAddress"
ref="shippingsAddressForm"
@ready="isReady => shippingAddressReadyToSubmit = isReady"
/>
Expand All @@ -29,13 +35,15 @@

<script>
import BaseButton from '../BaseButton.vue'
import CustomerAddresses from '../CustomerAddresses.vue'
import CustomerEmailField from '../CustomerEmailField.vue'
import ShippingAddressForm from '../ShippingAddressForm.vue'
import ShippingMethods from '../ShippingMethods.vue'

export default {
components: {
BaseButton,
CustomerAddresses,
CustomerEmailField,
ShippingAddressForm,
ShippingMethods
Expand All @@ -45,7 +53,8 @@ export default {
customerEmailReadyToSubmit: false,
shippingMethodsReadyToSubmit: false,
shippingAddressReadyToSubmit: false,
loader: false
loader: false,
newAddress: false
}
},
computed: {
Expand Down Expand Up @@ -80,6 +89,9 @@ export default {
})

this.$store.dispatch('getTotals')
},
addNewAddress () {
this.newAddress = !this.newAddress
}
}
}
Expand Down