solution: get the product by id

This commit is contained in:
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> </div>
<div class="product__actions"> <div class="product__actions">
<button @click="addProductToCart({ id, title, price, image })"> <button @click="addProductToCart({ id })">
Add to Cart Add to Cart
</button> </button>
</div> </div>

View File

@ -1,6 +1,9 @@
export default { export default {
addProductToCart(context, payload) { 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) { removeProductFromCart(context, payload) {
context.commit('removeProductFromCart', payload); context.commit('removeProductFromCart', payload);