You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to report some errors that I have found in your add_cart_item controller. These issues have gone unnoticed and I believe they need to be addressed. Here are the details:
When an item is added to the cart and there are existing items in the cart (if(itemIndex > -1){...}), the price of the new item(s) is not being updated. This could lead to incorrect billing and confusion for the user.
Similarly, when there are existing items in the cart (if(itemIndex > -1){...}), the old total price of the item is not being subtracted from the bill. This could cause issues if the admin changes the price of a product item and the user ends up buying it at the old price.
To resolve these issues, I suggest the following new code:
if (itemIndex > -1) {
let productItem = cart.items[itemIndex];
cart.bill -= productItem.quantity * productItem.price; // Subtract the old total price of the item from the bill
productItem.quantity += quantity;
productItem.price = price * productItem.quantity; // Update the price of the item in the cart
cart.items[itemIndex] = productItem;
} else {
cart.items.push({ productId, name, quantity, price: price * quantity });
}
The text was updated successfully, but these errors were encountered:
I would like to report some errors that I have found in your add_cart_item controller. These issues have gone unnoticed and I believe they need to be addressed. Here are the details:
When an item is added to the cart and there are existing items in the cart (if(itemIndex > -1){...}), the price of the new item(s) is not being updated. This could lead to incorrect billing and confusion for the user.
Similarly, when there are existing items in the cart (if(itemIndex > -1){...}), the old total price of the item is not being subtracted from the bill. This could cause issues if the admin changes the price of a product item and the user ends up buying it at the old price.
To resolve these issues, I suggest the following new code:
if (itemIndex > -1) {
let productItem = cart.items[itemIndex];
cart.bill -= productItem.quantity * productItem.price; // Subtract the old total price of the item from the bill
productItem.quantity += quantity;
productItem.price = price * productItem.quantity; // Update the price of the item in the cart
cart.items[itemIndex] = productItem;
} else {
cart.items.push({ productId, name, quantity, price: price * quantity });
}
The text was updated successfully, but these errors were encountered: