|
@@ -1,15 +1,15 @@
|
|
<template>
|
|
<template>
|
|
<div class="cart">
|
|
<div class="cart">
|
|
<h2>Your Cart</h2>
|
|
<h2>Your Cart</h2>
|
|
- <p v-show="!cart.added.length"><i>Please add some products to cart.</i></p>
|
|
|
|
|
|
+ <p v-show="!products.length"><i>Please add some products to cart.</i></p>
|
|
<ul>
|
|
<ul>
|
|
<li v-for="p in products">
|
|
<li v-for="p in products">
|
|
{{ p.title }} - {{ p.price | currency }} x {{ p.quantity }}
|
|
{{ p.title }} - {{ p.price | currency }} x {{ p.quantity }}
|
|
</li>
|
|
</li>
|
|
</ul>
|
|
</ul>
|
|
<p>Total: {{ total | currency }}</p>
|
|
<p>Total: {{ total | currency }}</p>
|
|
- <p><button :disabled="!cart.added.length" @click="checkout">Checkout</button></p>
|
|
|
|
- <p v-show="cart.lastCheckout">Checkout {{ cart.lastCheckout }}.</p>
|
|
|
|
|
|
+ <p><button :disabled="!products.length" @click="checkout">Checkout</button></p>
|
|
|
|
+ <p v-show="checkoutStatus">Checkout {{ checkoutStatus }}.</p>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
@@ -18,14 +18,9 @@ import vuex from '../vuex'
|
|
const { checkout } = vuex.actions
|
|
const { checkout } = vuex.actions
|
|
|
|
|
|
export default {
|
|
export default {
|
|
- data () {
|
|
|
|
- return {
|
|
|
|
- cart: vuex.get('cart')
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
computed: {
|
|
computed: {
|
|
products () {
|
|
products () {
|
|
- return this.cart.added.map(({ id, quantity }) => {
|
|
|
|
|
|
+ return vuex.state.cart.added.map(({ id, quantity }) => {
|
|
const product = vuex.state.products.find(p => p.id === id)
|
|
const product = vuex.state.products.find(p => p.id === id)
|
|
return {
|
|
return {
|
|
title: product.title,
|
|
title: product.title,
|
|
@@ -34,6 +29,9 @@ export default {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
+ checkoutStatus () {
|
|
|
|
+ return vuex.state.cart.lastCheckout
|
|
|
|
+ },
|
|
total () {
|
|
total () {
|
|
return this.products.reduce((total, p) => {
|
|
return this.products.reduce((total, p) => {
|
|
return total + p.price * p.quantity
|
|
return total + p.price * p.quantity
|