nagasurendra commited on
Commit
8de243f
·
verified ·
1 Parent(s): 8797416

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +16 -10
templates/cart.html CHANGED
@@ -256,6 +256,11 @@
256
  })
257
  .catch(err => console.error("Error:", err));
258
  }
 
 
 
 
 
259
  function calculateDiscount() {
260
  const subtotal = parseFloat("{{ subtotal }}");
261
  const discountElement = document.getElementById('discountText');
@@ -286,26 +291,27 @@
286
  document.querySelector('.cart-summary p').innerText = `Subtotal: $${subtotal.toFixed(2)}`;
287
  return subtotal;
288
  }
289
-
290
-
291
  function proceedToOrder() {
292
- const checkbox = document.getElementById('rewardCheckbox');
293
- let useRewardPoints = false;
294
- if (checkbox) {
295
- // If the checkbox exists, get its checked status
296
- useRewardPoints = checkbox.checked;
297
- }
298
 
299
  fetch('/checkout', {
300
  method: 'POST',
301
  headers: { 'Content-Type': 'application/json' },
302
- body: JSON.stringify({ useRewardPoints: useRewardPoints })
 
 
 
303
  })
304
  .then(response => response.json())
305
  .then(data => {
306
  if (data.success) {
307
  alert(data.message);
308
- window.location.href = '/order'; // Redirect to menu or order confirmation page
309
  } else {
310
  alert(data.error || data.message);
311
  }
 
256
  })
257
  .catch(err => console.error("Error:", err));
258
  }
259
+ function toggleCouponDropdown() {
260
+ let couponCheckbox = document.getElementById('couponCheckbox');
261
+ let couponDropdown = document.getElementById('couponDropdown');
262
+ couponDropdown.disabled = !couponCheckbox.checked;
263
+ }
264
  function calculateDiscount() {
265
  const subtotal = parseFloat("{{ subtotal }}");
266
  const discountElement = document.getElementById('discountText');
 
291
  document.querySelector('.cart-summary p').innerText = `Subtotal: $${subtotal.toFixed(2)}`;
292
  return subtotal;
293
  }
 
 
294
  function proceedToOrder() {
295
+ const rewardCheckbox = document.getElementById('rewardCheckbox');
296
+ let useRewardPoints = rewardCheckbox ? rewardCheckbox.checked : false;
297
+
298
+ const couponCheckbox = document.getElementById('couponCheckbox');
299
+ const couponDropdown = document.getElementById('couponDropdown');
300
+ let selectedCoupon = couponCheckbox.checked ? couponDropdown.value : "";
301
 
302
  fetch('/checkout', {
303
  method: 'POST',
304
  headers: { 'Content-Type': 'application/json' },
305
+ body: JSON.stringify({
306
+ useRewardPoints: useRewardPoints,
307
+ selectedCoupon: selectedCoupon // Send selected coupon to backend
308
+ })
309
  })
310
  .then(response => response.json())
311
  .then(data => {
312
  if (data.success) {
313
  alert(data.message);
314
+ window.location.href = '/order'; // Redirect to order confirmation
315
  } else {
316
  alert(data.error || data.message);
317
  }