Rammohan0504 commited on
Commit
d3717de
·
verified ·
1 Parent(s): b05c005

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +82 -175
templates/cart.html CHANGED
@@ -3,200 +3,127 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>Cart</title>
7
- <!-- Bootstrap CSS -->
8
- <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
9
  <style>
10
  body {
11
  font-family: Arial, sans-serif;
12
  background-color: #f8f9fa;
 
 
13
  }
14
- .cart-container {
15
  max-width: 768px;
16
  margin: 20px auto;
17
- padding: 15px;
18
  background-color: #fff;
19
  border-radius: 10px;
20
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
 
21
  }
22
- .cart-item {
23
- display: flex;
24
- align-items: center;
25
- justify-content: space-between;
26
- border-bottom: 1px solid #dee2e6;
27
- padding: 10px 0;
28
  }
29
- .cart-item img {
30
- width: 70px;
31
- height: 70px;
32
- object-fit: cover;
33
- border-radius: 5px;
34
  }
35
- .cart-item-details {
36
- flex: 1;
37
- margin-left: 15px;
38
  }
39
- .cart-item-title {
 
 
40
  font-size: 1rem;
41
- font-weight: bold;
42
  }
43
- .cart-item-quantity {
44
- display: flex;
45
- align-items: center;
46
- margin-top: 5px;
47
- }
48
- .cart-item-quantity button {
49
- width: 30px;
50
- height: 30px;
51
- border: none;
52
- background-color: #f0f0f0;
53
- font-size: 1rem;
54
  font-weight: bold;
55
- cursor: pointer;
56
- }
57
- .cart-item-quantity input {
58
- width: 40px;
59
- text-align: center;
60
- border: none;
61
- background-color: #f8f9fa;
62
- font-size: 1rem;
63
- margin: 0 5px;
64
- }
65
- .cart-summary {
66
- text-align: right;
67
  margin-top: 15px;
68
  }
69
- .checkout-button {
70
- background-color: #007bff;
71
- color: #fff;
72
  padding: 10px;
 
73
  border-radius: 5px;
74
- border: none;
75
- width: 100%;
76
- font-size: 1.2rem;
77
- cursor: pointer;
78
- margin-top: 10px;
79
- }
80
- .apply-coupon {
81
- margin-top: 20px;
82
- text-align: right;
83
  }
84
- .apply-coupon select, .apply-coupon button {
 
 
85
  font-size: 1rem;
 
86
  }
87
- .apply-coupon button {
 
88
  background-color: #28a745;
89
  color: white;
90
- padding: 5px 15px;
91
  border: none;
 
92
  cursor: pointer;
93
  }
94
- .apply-coupon button:hover {
95
  background-color: #218838;
96
  }
97
- .coupon-message {
98
- margin-top: 10px;
 
 
 
99
  font-size: 1rem;
100
- color: red;
 
 
 
 
 
101
  }
102
  </style>
103
  </head>
104
  <body>
105
- <div class="container">
106
- <div class="cart-container">
107
- <div style="text-align: right;">
108
- <a href="/menu" style="text-decoration: none; font-size: 1.5rem; color: #007bff;">&times;</a>
 
 
 
 
109
  </div>
110
-
111
- <h4 class="mb-4">Your Cart</h4>
112
-
113
- <!-- Cart Items -->
114
- {% for item in cart_items %}
115
- <div class="cart-item">
116
- <img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
117
- <div class="cart-item-details">
118
- <div class="cart-item-title">{{ item.Name }}</div>
119
- <div class="cart-item-addons">
120
- <small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
121
- </div>
122
- <div class="cart-item-instructions">
123
- <small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
124
- </div>
125
- <div class="cart-item-quantity mt-2">
126
- <!-- Decrease button -->
127
- <button onclick="updateQuantity('decrease', '{{ item.Name }}', '{{ customer_email }}')">-</button>
128
- <!-- Quantity input field -->
129
- <input type="text" value="{{ item.Quantity__c }}" readonly data-item-name="{{ item.Name }}">
130
- <!-- Increase button -->
131
- <button onclick="updateQuantity('increase', '{{ item.Name }}', '{{ customer_email }}')">+</button>
132
- </div>
133
- </div>
134
- <div class="cart-item-actions">
135
- <div class="text-primary">
136
- $<span class="base-price">{{ item.Price__c }}</span>
137
- </div>
138
-
139
- <button class="btn btn-danger btn-sm" onclick="removeItemFromCart('{{ item.Name }}')">Remove</button>
140
- </div>
141
  </div>
142
- {% else %}
143
- <p class="text-center">Your cart is empty.</p>
144
- {% endfor %}
145
 
146
- <!-- Apply Coupon Section -->
147
- <div class="apply-coupon">
148
- <label for="coupon-code">Coupon Code:</label>
149
- <select id="coupon-code" name="coupon_code">
150
- <option value="">Select a coupon code</option>
151
- {% for coupon in coupon_codes %}
152
- <option value="{{ coupon.Coupon_Code__c }}">{{ coupon.Coupon_Code__c }}</option>
153
- {% endfor %}
154
- </select>
155
- <button type="button" onclick="applyCoupon()">Apply Coupon</button>
156
- <p id="coupon-message" class="coupon-message"></p>
157
  </div>
158
 
159
- <!-- Subtotal -->
160
- <div class="cart-summary">
161
- <p class="fw-bold">Subtotal: ${{ subtotal }}</p>
162
- <button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
163
  </div>
164
  </div>
165
- </div>
166
 
167
- <script>
168
- // Fetch coupon codes automatically when the page loads
169
- document.addEventListener("DOMContentLoaded", function() {
170
- const customerEmail = "{{ customer_email }}"; // The email stored in the session
 
171
 
172
- if (customerEmail) {
173
- fetch(`/get_coupon_codes?email=${customerEmail}`)
174
- .then(response => response.json())
175
- .then(data => {
176
- if (data.success && data.coupon_codes) {
177
- const couponSelect = document.getElementById('coupon-code');
178
- data.coupon_codes.forEach(coupon => {
179
- const option = document.createElement('option');
180
- option.value = coupon.Coupon_Code__c;
181
- option.textContent = coupon.Coupon_Code__c;
182
- couponSelect.appendChild(option);
183
- });
184
- } else {
185
- document.getElementById('coupon-message').innerText = "No active coupons found for your account.";
186
- document.getElementById('coupon-message').style.color = "red";
187
- }
188
- })
189
- .catch(error => {
190
- console.error('Error fetching coupon codes:', error);
191
- });
192
- }
193
- });
194
 
195
- // Apply coupon and discount
 
196
  function applyCoupon() {
197
- const couponCode = document.getElementById('coupon-code').value;
198
- const subtotal = parseFloat(document.getElementById('subtotal').innerText.replace('$', ''));
199
- const couponMessage = document.getElementById('coupon-message');
200
 
201
  if (couponCode) {
202
  fetch('/apply_coupon', {
@@ -209,44 +136,24 @@
209
  .then(response => response.json())
210
  .then(data => {
211
  if (data.success) {
 
212
  const discount = data.discount;
213
- const totalPrice = subtotal - discount;
214
- document.getElementById('discount').innerText = discount.toFixed(2);
215
- document.getElementById('total-price').innerText = totalPrice.toFixed(2);
216
- couponMessage.innerText = `Coupon applied! You saved $${discount.toFixed(2)}`;
217
- couponMessage.style.color = 'green';
218
  } else {
219
- couponMessage.innerText = data.message;
220
- couponMessage.style.color = 'red';
221
  }
222
  })
223
  .catch(error => {
224
  console.error('Error applying coupon:', error);
225
- couponMessage.innerText = 'Error applying coupon.';
226
- couponMessage.style.color = 'red';
227
  });
228
  } else {
229
- couponMessage.innerText = 'Please select a coupon code.';
230
- couponMessage.style.color = 'red';
231
  }
232
  }
233
-
234
- function proceedToOrder() {
235
- fetch('/checkout', {
236
- method: 'POST',
237
- })
238
- .then(response => response.json())
239
- .then(data => {
240
- if (data.success) {
241
- alert(data.message);
242
- window.location.href = '/order'; // Redirect to menu or order confirmation page
243
- } else {
244
- alert(data.error || data.message);
245
- }
246
- })
247
- .catch(err => console.error('Error during checkout:', err));
248
- }
249
  </script>
250
-
251
  </body>
252
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Your Order Summary</title>
 
 
7
  <style>
8
  body {
9
  font-family: Arial, sans-serif;
10
  background-color: #f8f9fa;
11
+ margin: 0;
12
+ padding: 0;
13
  }
14
+ .order-container {
15
  max-width: 768px;
16
  margin: 20px auto;
17
+ padding: 20px;
18
  background-color: #fff;
19
  border-radius: 10px;
20
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
21
+ text-align: center;
22
  }
23
+ h2 {
24
+ color: #FF5722;
25
+ font-size: 2rem;
 
 
 
26
  }
27
+ .order-summary {
28
+ margin-top: 20px;
29
+ text-align: left;
30
+ font-size: 1.2rem;
 
31
  }
32
+ .order-summary .item {
33
+ margin-bottom: 10px;
 
34
  }
35
+ .order-summary .item span {
36
+ display: inline-block;
37
+ width: 100%;
38
  font-size: 1rem;
39
+ color: #333;
40
  }
41
+ .total-price {
42
+ font-size: 1.5rem;
 
 
 
 
 
 
 
 
 
43
  font-weight: bold;
 
 
 
 
 
 
 
 
 
 
 
 
44
  margin-top: 15px;
45
  }
46
+ .apply-coupon-section {
47
+ margin-top: 20px;
 
48
  padding: 10px;
49
+ background-color: #f1f1f1;
50
  border-radius: 5px;
 
 
 
 
 
 
 
 
 
51
  }
52
+ .apply-coupon-section input {
53
+ width: 80%;
54
+ padding: 8px;
55
  font-size: 1rem;
56
+ margin-right: 10px;
57
  }
58
+ .apply-coupon-section button {
59
+ padding: 10px 20px;
60
  background-color: #28a745;
61
  color: white;
62
+ font-size: 1rem;
63
  border: none;
64
+ border-radius: 5px;
65
  cursor: pointer;
66
  }
67
+ .apply-coupon-section button:hover {
68
  background-color: #218838;
69
  }
70
+ .back-to-menu {
71
+ margin-top: 30px;
72
+ padding: 10px 20px;
73
+ background-color: #007bff;
74
+ color: white;
75
  font-size: 1rem;
76
+ border: none;
77
+ border-radius: 5px;
78
+ cursor: pointer;
79
+ }
80
+ .back-to-menu:hover {
81
+ background-color: #0056b3;
82
  }
83
  </style>
84
  </head>
85
  <body>
86
+ <div class="order-container">
87
+ <h2>Your Order Summary</h2>
88
+
89
+ <!-- Order Details Section -->
90
+ <div class="order-summary">
91
+ <div class="item" id="item1">
92
+ <span>Chicken Curry (Qty: 1.0, Add-Ons: None, Price: $14.00)</span>
93
+ <span id="price1">$14.00</span>
94
  </div>
95
+ <div class="item" id="item2">
96
+ <span>Sukka Gosht (Goat) (Qty: 1.0, Add-Ons: None, Price: $18.00)</span>
97
+ <span id="price2">$18.00</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  </div>
 
 
 
99
 
100
+ <!-- Discount Section -->
101
+ <div class="item" id="discountSection">
102
+ <span>Discount: $<span id="discountAmount">0.00</span></span>
 
 
 
 
 
 
 
 
103
  </div>
104
 
105
+ <!-- Total Price Section -->
106
+ <div class="total-price">
107
+ Total: $<span id="totalAmount">32.00</span>
 
108
  </div>
109
  </div>
 
110
 
111
+ <!-- Apply Coupon Section -->
112
+ <div class="apply-coupon-section">
113
+ <input type="text" id="couponCode" placeholder="Enter coupon code" />
114
+ <button onclick="applyCoupon()">Apply Coupon</button>
115
+ </div>
116
 
117
+ <!-- Back to Menu Button -->
118
+ <button class="back-to-menu" onclick="window.location.href='/menu'">Back to Menu</button>
119
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
+ <script>
122
+ // Function to apply the coupon
123
  function applyCoupon() {
124
+ const couponCode = document.getElementById('couponCode').value;
125
+ const subtotal = 32.00; // Hardcoded subtotal for this example (replace it with dynamic value)
126
+ const couponMessage = document.getElementById('couponMessage');
127
 
128
  if (couponCode) {
129
  fetch('/apply_coupon', {
 
136
  .then(response => response.json())
137
  .then(data => {
138
  if (data.success) {
139
+ // Calculate and update the discount and total price
140
  const discount = data.discount;
141
+ const total = subtotal - discount;
142
+
143
+ document.getElementById('discountAmount').innerText = discount.toFixed(2);
144
+ document.getElementById('totalAmount').innerText = total.toFixed(2);
 
145
  } else {
146
+ alert(data.message); // Show error message if coupon is invalid
 
147
  }
148
  })
149
  .catch(error => {
150
  console.error('Error applying coupon:', error);
151
+ alert('Error applying coupon.');
 
152
  });
153
  } else {
154
+ alert('Please enter a coupon code');
 
155
  }
156
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  </script>
 
158
  </body>
159
  </html>