Subbu1304 commited on
Commit
e6ee870
·
verified ·
1 Parent(s): 8710331

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +7 -9
templates/cart.html CHANGED
@@ -258,15 +258,15 @@
258
  // })
259
  // .catch(err => console.error("Error:", err));
260
  // }
261
- function updateQuantity(action, itemName, customerEmail) {
262
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
263
- let quantity = parseInt(quantityInput.value, 10); // Get the value as an integer
264
 
265
  // Update quantity based on action
266
  if (action === 'increase') {
267
- quantity++; // Simply increase by 1
268
  } else if (action === 'decrease' && quantity > 1) {
269
- quantity--; // Simply decrease by 1, ensuring the quantity doesn't go below 1
270
  }
271
 
272
  // Ensure the quantity is a valid whole number and greater than 0
@@ -285,11 +285,9 @@
285
  .then(data => {
286
  if (data.success) {
287
  // Update the item price and quantity in the UI
288
- quantityInput.value = quantity; // Set the value as an integer
289
-
290
- // Make sure the value is displayed as an integer (no decimals)
291
- quantityInput.value = Math.floor(quantityInput.value);
292
 
 
293
  let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
294
  if (itemElement) {
295
  let basePriceElement = itemElement.querySelector(".base-price");
@@ -297,7 +295,7 @@
297
 
298
  // Update the base price
299
  if (basePriceElement) {
300
- basePriceElement.innerText = data.new_item_price.toFixed(2); // Assuming backend sends this
301
  }
302
 
303
  // Update add-ons price if needed (optional)
 
258
  // })
259
  // .catch(err => console.error("Error:", err));
260
  // }
261
+ function updateQuantity(action, itemName, customerEmail) {
262
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
263
+ let quantity = parseInt(quantityInput.value, 10); // Ensure we are working with an integer value
264
 
265
  // Update quantity based on action
266
  if (action === 'increase') {
267
+ quantity = Math.floor(quantity) + 1; // Ensure the quantity is an integer
268
  } else if (action === 'decrease' && quantity > 1) {
269
+ quantity = Math.floor(quantity) - 1; // Ensure the quantity is an integer
270
  }
271
 
272
  // Ensure the quantity is a valid whole number and greater than 0
 
285
  .then(data => {
286
  if (data.success) {
287
  // Update the item price and quantity in the UI
288
+ quantityInput.value = quantity; // Update quantity on the UI
 
 
 
289
 
290
+ // Update the base price based on the new quantity
291
  let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
292
  if (itemElement) {
293
  let basePriceElement = itemElement.querySelector(".base-price");
 
295
 
296
  // Update the base price
297
  if (basePriceElement) {
298
+ basePriceElement.innerText = data.new_item_price.toFixed(2);
299
  }
300
 
301
  // Update add-ons price if needed (optional)