From ba0dfd3622d5a72b07fc1085b235383b20a6f9b1 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 25 Jul 2021 16:45:55 +0200 Subject: Allow product removal on Checkout page. --- client/src/store/index.js | 4 ++-- client/src/views/Checkout.vue | 6 ++++++ client/src/views/Product.vue | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'client/src') diff --git a/client/src/store/index.js b/client/src/store/index.js index 086c544..519347d 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -58,8 +58,8 @@ export default createStore({ quantity: 1 }); }, - removeFromCart(state) { - let foundProduct = state.cart.find(x => x.id == state.currentProduct._id); + removeFromCart(state, productId) { + let foundProduct = state.cart.find(x => x.id == productId); if (foundProduct) { foundProduct.quantity--; if (foundProduct.quantity == 0) diff --git a/client/src/views/Checkout.vue b/client/src/views/Checkout.vue index 83d0940..8adeb4a 100644 --- a/client/src/views/Checkout.vue +++ b/client/src/views/Checkout.vue @@ -10,6 +10,7 @@ ${{ item.price }} {{ item.quantity }} + x

You can buy {{ cartSize }} items for ${{ cartPrice }}.

@@ -31,6 +32,11 @@ export default { cartPrice() { return this.$store.getters.getCartPrice; } + }, + methods: { + remove(id) { + this.$store.commit('removeFromCart', id); + } } } diff --git a/client/src/views/Product.vue b/client/src/views/Product.vue index ff43857..d1fde29 100644 --- a/client/src/views/Product.vue +++ b/client/src/views/Product.vue @@ -47,7 +47,7 @@ export default { this.$store.commit('addToCart'); }, remove() { - this.$store.commit('removeFromCart'); + this.$store.commit('removeFromCart', this.$route.params.id); } } } -- cgit v1.2.3