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

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +10 -9
templates/cart.html CHANGED
@@ -258,18 +258,18 @@
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 = Math.floor(quantity) + 1; // Ensure quantity remains an integer
268
  } else if (action === 'decrease' && quantity > 1) {
269
- quantity = Math.floor(quantity) - 1; // Ensure quantity remains an integer
270
  }
271
 
272
- // Ensure quantity is a valid whole number (integer) and greater than 0
273
  if (isNaN(quantity) || quantity < 1) {
274
  alert("Invalid quantity! Quantity should be a whole number.");
275
  return;
@@ -285,10 +285,10 @@
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 (no decimals)
289
 
290
  // Make sure the value is displayed as an integer (no decimals)
291
- quantityInput.value = parseInt(quantityInput.value, 10);
292
 
293
  let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
294
  if (itemElement) {
@@ -297,7 +297,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)
@@ -317,6 +317,7 @@
317
  .catch(err => console.error("Error:", err));
318
  }
319
 
 
320
  function updateQuantity(action, itemName, customerEmail) {
321
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
322
  let quantity = parseInt(quantityInput.value); // Get the value as an integer
 
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
273
  if (isNaN(quantity) || quantity < 1) {
274
  alert("Invalid quantity! Quantity should be a whole number.");
275
  return;
 
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) {
 
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)
 
317
  .catch(err => console.error("Error:", err));
318
  }
319
 
320
+
321
  function updateQuantity(action, itemName, customerEmail) {
322
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
323
  let quantity = parseInt(quantityInput.value); // Get the value as an integer