solution: get the product by id
This commit is contained in:
parent
787b44dc13
commit
88753af7e5
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in New Issue