nagasurendra commited on
Commit
62fda23
·
verified ·
1 Parent(s): 3fcfddd

Delete cart_update.js

Browse files
Files changed (1) hide show
  1. cart_update.js +0 -92
cart_update.js DELETED
@@ -1,92 +0,0 @@
1
- function updateCartDisplay() {
2
- let totalBill = 0;
3
- let cartHTML = "<h3>Your Cart:</h3><ul style='list-style: none; padding: 0;'>";
4
- cart.forEach((item, index) => {
5
- totalBill += item.itemTotal;
6
- const extras = item.extras.map((extra, i) => {
7
- const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
8
- const extraTotal = extrasPrices[extra] * extraQuantity;
9
- totalBill += extraTotal;
10
- return `<li>
11
- <div style='display: flex; justify-content: space-between; align-items: center;'>
12
- <span>${extra}</span>
13
- <span>Price: $${extrasPrices[extra].toFixed(2)}</span>
14
- <div>
15
- <label for='extra-quantity-${index}-${i}'>Quantity:</label>
16
- <input type='number' id='extra-quantity-${index}-${i}' value='${extraQuantity}' min='1' style='width: 50px;' onchange='updateExtraQuantity(${index}, ${i}, this.value)'>
17
- </div>
18
- <span>Total: $${extraTotal.toFixed(2)}</span>
19
- <input type='checkbox' id='extra-remove-${index}-${i}' onclick='removeExtra(${index}, ${i})'> Remove
20
- </div>
21
- </li>`;
22
- }).join('');
23
-
24
- cartHTML += `<li style='border-bottom: 1px solid #ddd; margin-bottom: 10px;'>
25
- <div style='display: flex; justify-content: space-between; align-items: center;'>
26
- <span>${item.name}</span>
27
- <span>Item Price: $${item.price.toFixed(2)}</span>
28
- <div>
29
- <label for='item-quantity-${index}'>Quantity:</label>
30
- <input type='number' id='item-quantity-${index}' value='${item.quantity}' min='1' style='width: 50px;' onchange='updateItemQuantity(${index}, this.value)'>
31
- </div>
32
- <span>Total: $${(item.price * item.quantity).toFixed(2)}</span>
33
- <input type='checkbox' id='item-remove-${index}' onclick='removeItem(${index})'> Remove
34
- </div>
35
- <div style='margin-left: 20px;'>
36
- <h4>Extras:</h4>
37
- <ul style='list-style: none; padding: 0;'>${extras}</ul>
38
- </div>
39
- <div style='margin-left: 20px;'>
40
- <strong>Instructions:</strong> ${item.instructions || "None"}
41
- </div>
42
- </li>`;
43
- });
44
- cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
45
- cartHTML += `<button style='margin-top: 10px; background-color: #007bff; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer;' onclick='submitCart()'>Submit</button>`;
46
- document.getElementById('floating-cart').innerHTML = cartHTML;
47
- }
48
-
49
- function updateItemQuantity(index, newQuantity) {
50
- const quantity = parseInt(newQuantity) || 1;
51
- cart[index].quantity = quantity;
52
- cart[index].itemTotal = cart[index].price * quantity;
53
- updateCartDisplay();
54
- }
55
-
56
- function updateExtraQuantity(cartIndex, extraIndex, newQuantity) {
57
- const quantity = parseInt(newQuantity) || 1;
58
- cart[cartIndex].extrasQuantities = cart[cartIndex].extrasQuantities || [];
59
- cart[cartIndex].extrasQuantities[extraIndex] = quantity;
60
- updateCartDisplay();
61
- }
62
-
63
- function removeExtra(cartIndex, extraIndex) {
64
- cart[cartIndex].extras.splice(extraIndex, 1);
65
- if (cart[cartIndex].extrasQuantities) {
66
- cart[cartIndex].extrasQuantities.splice(extraIndex, 1);
67
- }
68
- updateCartDisplay();
69
- }
70
-
71
- function submitCart() {
72
- let finalOrderHTML = "<h3>Final Order:</h3><ul>";
73
- let totalBill = 0;
74
- cart.forEach(item => {
75
- totalBill += item.itemTotal;
76
- const extras = item.extras.map((extra, i) => {
77
- const extraQuantity = item.extrasQuantities ? item.extrasQuantities[i] || 1 : 1;
78
- const extraTotal = extrasPrices[extra] * extraQuantity;
79
- totalBill += extraTotal;
80
- return `${extra} (x${extraQuantity}) - $${extraTotal.toFixed(2)}`;
81
- }).join(', ');
82
-
83
- finalOrderHTML += `<li>
84
- ${item.name} (x${item.quantity}) - $${item.itemTotal.toFixed(2)}
85
- <br>Extras: ${extras}
86
- <br>Instructions: ${item.instructions || "None"}
87
- </li>`;
88
- });
89
- finalOrderHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
90
- document.getElementById('final-order').innerHTML = finalOrderHTML;
91
- alert("Your final order has been submitted!");
92
- }