addToCart (event: any) {
if ("cart" in localStorage) {
this.cartProducts = JSON.parse(localStorage.getItem("cart")!)
console.log(event);
let exist = this.cartProducts.find(item => item.item.id == event.item.id);
if(exist) {
alert("This product is already in your cart");
} else {
this.cartProducts.push(event);
localStorage.setItem("cart" , JSON.stringify(this.cartProducts));
}
}else {
this.cartProducts.push(event);
localStorage.setItem("cart" , JSON.stringify(this.cartProducts));
}
}
Your unique content goes here.
I attempted to address this issue using type annotation, but unfortunately, I was unable to find a quick solution. It seems there is no easy fix for this problem at the moment.