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