Here I am having the onclick function which is get the Product_id, Product_name and Price from detailss array. I am storing this value using local storage array wishlist.
Now I am stuck to update the quantity in local storage array wishlist, I need to add the quantity if the productid already present in local storage.
addToCart(Product_id){
var name=[{
Product_id:this.detailss[0].Product_id,
Product_name:this.detailss[0].Product_name,
Price:this.detailss[0].Price,
Quantity:"",
}];
var a = JSON.parse(localStorage.getItem('wishlist')) || [];
a.push(name);
localStorage.setItem('wishlist', JSON.stringify(a));
console.log(Product_id);
}
Thanks in advance.
Function that only adds amount if item exists.
In this example amount is added by clicking on + button inside the cart:
If you want to pass a number:
P.S. It's better to use Storage instead of
localStoragefor that kind of data.