My goal is to adjust the price when the user clicks on the minus icon. However, I want the new price after decreasing to revert back to the initial price.
quantityHandler: function (action, product) {
// Increase or decrease quantity of product
try {
const newItems = [...this.products]; // clone the array
let idx = newItems.indexOf(product);
let currentQty = newItems[idx].productQuantity;
let price = newItems[idx].unitPrice;
if (action == "more") {
newItems[idx].productQuantity = currentQty + 1;
newItems[idx].unitPrice = price + price;
} else if (action == "less") {
newItems[idx].productQuantity = currentQty > 1 ? currentQty - 1 : 1;
// Decrease the current price using the original price
}
this.products = newItems; // set new state
console.log(this.products);
} catch (error) {
alert(error);
}
},