let items = JSON.parse(localStorage.getItem('cart')) || [];
let newItem = {};
$.each(items, function () {
if (newItem.order_id == this.order.id) {
newItem.order_id = '1';
newItem.order_name = 'cake';
newItem.price = '$1.10';
newItem.qty = 1;
newItem.qty = parseInt(this.qty) + 1;
} else {
newItem.order_id = '1';
newItem.order_name = 'cake';
newItem.price = '$1.10';
newItem.qty = 1;
}
});
items.push(newItem);
localStorage.setItem('cart', JSON.stringify(items));
Is there a way to adjust the quantity of an order when the order_id already exists in localStorage? The code snippet above adds another set of array objects even though the quantity part is correct.