nagasurendra commited on
Commit
5b607ed
·
verified ·
1 Parent(s): 9c827f0

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +17 -3
templates/cart.html CHANGED
@@ -202,9 +202,23 @@
202
  if (data.success) {
203
  // Update the item price and quantity in the UI
204
  quantityInput.value = quantity;
205
- let itemPriceElement = document.querySelector(`[data-item-name="${itemName}"] .base-price`);
206
- itemPriceElement.innerText = data.new_item_price.toFixed(2);
207
- document.querySelector('.cart-summary p').innerText = `Subtotal: $${data.subtotal.toFixed(2)}`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  location.reload();
209
 
210
  // Recalculate subtotal dynamically
 
202
  if (data.success) {
203
  // Update the item price and quantity in the UI
204
  quantityInput.value = quantity;
205
+ let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
206
+ if (itemElement) {
207
+ let basePriceElement = itemElement.querySelector(".base-price");
208
+ let addonsPriceElement = itemElement.querySelector(".addons-price");
209
+
210
+ // Update the base price
211
+ if (basePriceElement) {
212
+ basePriceElement.innerText = data.new_item_price.toFixed(2); // Assuming backend sends this
213
+ }
214
+
215
+ // Update add-ons price if needed (optional)
216
+ if (addonsPriceElement && data.addons_price !== undefined) {
217
+ addonsPriceElement.innerText = data.addons_price.toFixed(2);
218
+ }
219
+ } else {
220
+ console.error(`Parent cart item element not found for item: ${itemName}`);
221
+ }
222
  location.reload();
223
 
224
  // Recalculate subtotal dynamically