This my cart code it it work good with ProductVariants id perfectly work....but incrementToCart not work
{
export const addToCart = (product) => (dispatch, getState) => {
const cartItems = getState().cart.cartItems.slice();
if (!product.selectedVariant) {
product.selectedVariant = product.ProductVariants[0];
}
const existingProductIndex = cartItems.findIndex(p => p.id === product.id && p.selectedVariant.id === product.selectedVariant.id);
if (existingProductIndex > -1) {
cartItems[existingProductIndex].selectedVariant.qty += product.selectedVariant.qty;
NotificationManager.success("Successfully updated", "", 1500);
} else {
cartItems.push({ ...product });
NotificationManager.success("Successfully added", "", 1500);
}
dispatch({
type: ADD_TO_CART,
payload: { cartItems },
});
sessionStorage.setItem("cartItems", JSON.stringify(cartItems));
};
console.log - this data.....
id: 9, productId: 4, actualPrice: null, distributorPrice: 480, marginPer: 58
}
This is my incrementTocar code...here may be problem but I can't find so please help me....
export const incrementToCart = (product) => (dispatch, getState) => {
const cartItems = getState().cart.cartItems.slice()
const selectProduct = cartItems.find(item => item.id === product.productId)
const index = cartItems.indexOf(selectProduct)
const value = cartItems[index].ProductVariants[0];
console.log(value)
value.qty = value.qty + 1;
value.total = value.qty * value.netPrice;
dispatch({
type: INCREASE_QUANTITY,
payload: { cartItems },
});
NotificationManager.success("Successfully qnty updated", "", 1500);
sessionStorage.setItem("cartItems", JSON.stringify(cartItems));
}