solution: get the product by id

master
Andreas Zweili 2021-05-05 17:31:04 +02:00
parent 787b44dc13
commit 88753af7e5
2 changed files with 5 additions and 2 deletions

View File

@ -13,7 +13,7 @@
</div>
</div>
<div class="product__actions">
<button @click="addProductToCart({ id, title, price, image })">
<button @click="addProductToCart({ id })">
Add to Cart
</button>
</div>

View File

@ -1,6 +1,9 @@
export default {
addProductToCart(context, payload) {
context.commit('addProductToCart', payload);
const productId = payload.id;
const products = context.rootGetters['products/products'];
const product = products.find(product => product.id === productId);
context.commit('addProductToCart', product);
},
removeProductFromCart(context, payload) {
context.commit('removeProductFromCart', payload);