Rammohan0504 commited on
Commit
14c04be
·
verified ·
1 Parent(s): a350be0

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +114 -166
templates/cart.html CHANGED
@@ -3,8 +3,7 @@
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/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
9
  <style>
10
  body {
@@ -12,7 +11,7 @@
12
  background-color: #f8f9fa;
13
  }
14
  .cart-container {
15
- max-width: 768px;
16
  margin: 20px auto;
17
  padding: 15px;
18
  background-color: #fff;
@@ -21,8 +20,8 @@
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
  }
@@ -37,13 +36,12 @@
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;
@@ -66,224 +64,174 @@
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 input {
85
- width: 200px;
86
- padding: 5px;
87
- margin-right: 10px;
88
- }
89
- .apply-coupon button {
90
- background-color: #28a745;
91
- color: white;
92
- padding: 5px 15px;
93
- border: none;
94
- cursor: pointer;
95
- font-size: 1rem;
96
- }
97
- .apply-coupon button:hover {
98
- background-color: #218838;
99
- }
100
- .coupon-message {
101
- margin-top: 10px;
102
- font-size: 1rem;
103
  color: red;
104
- }
105
- .suggestion-section {
106
- margin-top: 20px;
107
- padding: 15px;
108
- background-color: #f8f9fa;
109
- border-radius: 10px;
110
- }
111
- .suggestion-item {
112
- display: flex;
113
- align-items: center;
114
- justify-content: space-between;
115
- padding: 10px 0;
116
- }
117
- .suggestion-item img {
118
- width: 50px;
119
- height: 50px;
120
- object-fit: cover;
121
- border-radius: 5px;
122
- }
123
- .add-back-button {
124
- padding: 5px 15px;
125
- font-size: 0.9rem;
126
- border-radius: 20px;
127
- border: 1px solid #007bff;
128
- color: #007bff;
129
- background-color: #fff;
130
- cursor: pointer;
131
- }
132
- .add-back-button:hover {
133
- background-color: #007bff;
134
- color: #fff;
135
  }
136
  </style>
137
  </head>
138
  <body>
139
  <div class="container">
140
  <div class="cart-container">
141
- <div style="text-align: right;">
142
- <a href="/menu" style="text-decoration: none; font-size: 1.5rem; color: #007bff;">&times;</a>
143
- </div>
144
-
145
- <h4 class="mb-4">Your Cart</h4>
146
-
147
  <!-- Cart Items -->
148
  {% for item in cart_items %}
149
  <div class="cart-item">
150
  <img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
151
  <div class="cart-item-details">
152
- <div class="cart-item-title">{{ item.Name }}</div>
153
- <div class="cart-item-addons">
154
- <small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
155
- </div>
156
- <div class="cart-item-instructions">
157
- <small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
158
- </div>
159
- <div class="cart-item-quantity mt-2">
160
- <!-- Decrease button -->
161
- <button onclick="updateQuantity('decrease', '{{ item.Name }}', '{{ customer_email }}')">-</button>
162
- <!-- Quantity input field -->
163
- <input type="text" value="{{ item.Quantity__c }}" readonly data-item-name="{{ item.Name }}">
164
- <!-- Increase button -->
165
- <button onclick="updateQuantity('increase', '{{ item.Name }}', '{{ customer_email }}')">+</button>
166
  </div>
167
  </div>
168
  <div class="cart-item-actions">
169
  <div class="text-primary">
170
- $<span class="base-price">{{ item.Price__c }}</span>
171
  </div>
172
-
173
- <button class="btn btn-danger btn-sm" onclick="removeItemFromCart('{{ item.Name }}')">Remove</button>
174
  </div>
175
  </div>
176
- {% else %}
177
- <p class="text-center">Your cart is empty.</p>
178
  {% endfor %}
179
 
180
- <!-- Apply Coupon Section -->
181
- <div class="apply-coupon">
182
- <label for="coupon-code">Coupon Code:</label>
183
- <input type="text" id="coupon-code" name="coupon_code" placeholder="Coupon code will appear here" readonly>
184
- <button type="button" onclick="applyCoupon()">Apply Coupon</button>
185
- <p id="coupon-message" class="coupon-message"></p>
186
  </div>
187
 
188
- <!-- Subtotal -->
 
 
189
  <div class="cart-summary">
190
- <p class="fw-bold">Subtotal: ${{ subtotal }}</p>
191
- <button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
 
192
  </div>
193
- </div>
194
 
195
- <!-- Suggestions Section -->
196
- <div class="suggestion-section">
197
- {% for suggestion in suggestions %}
198
- <div class="suggestion-item">
199
- <img src="{{ suggestion.Image1__c }}" alt="{{ suggestion.Name }}" onerror="this.src='/static/placeholder.jpg';">
200
- <div>
201
- <div>{{ suggestion.Name }}</div>
202
- <div class="text-muted">${{ suggestion.Price__c }}</div>
203
- </div>
204
- <button class="add-back-button" onclick="addSuggestion('{{ suggestion.Id }}')">Add</button>
205
- </div>
206
- {% endfor %}
207
  </div>
208
  </div>
209
 
210
  <script>
211
- // Fetch coupon code automatically when the page loads
212
  document.addEventListener("DOMContentLoaded", function() {
213
- const customerEmail = "{{ customer_email }}"; // The email stored in the session
214
-
215
- if (customerEmail) {
216
- fetch(`/get_coupon_code?email=${customerEmail}`)
217
- .then(response => response.json())
218
- .then(data => {
219
- if (data.success && data.coupon_code) {
220
- document.getElementById('coupon-code').value = data.coupon_code; // Set coupon code in the input
221
- } else {
222
- document.getElementById('coupon-message').innerText = "No coupon found for your account.";
223
- document.getElementById('coupon-message').style.color = "red";
224
- }
225
- })
226
- .catch(error => {
227
- console.error('Error fetching coupon code:', error);
228
- });
229
- }
230
- });
231
-
232
- // Apply coupon and discount
233
- function applyCoupon() {
234
- const couponCode = document.getElementById('coupon-code').value;
235
- const subtotal = parseFloat(document.getElementById('subtotal').innerText.replace('$', ''));
236
- const couponMessage = document.getElementById('coupon-message');
237
-
238
- if (couponCode) {
239
- fetch('/apply_coupon', {
240
- method: 'POST',
241
- headers: {
242
- 'Content-Type': 'application/json'
243
- },
244
- body: JSON.stringify({ coupon_code: couponCode, subtotal: subtotal })
245
- })
246
  .then(response => response.json())
247
  .then(data => {
248
  if (data.success) {
249
- const discount = data.discount;
250
- const totalPrice = subtotal - discount;
251
- document.getElementById('discount').innerText = discount.toFixed(2);
252
- document.getElementById('total-price').innerText = totalPrice.toFixed(2);
253
- couponMessage.innerText = `Coupon applied! You saved $${discount.toFixed(2)}`;
254
- couponMessage.style.color = 'green';
 
255
  } else {
256
- couponMessage.innerText = data.message;
257
- couponMessage.style.color = 'red';
258
  }
259
  })
260
- .catch(error => {
261
- console.error('Error applying coupon:', error);
262
- couponMessage.innerText = 'Error applying coupon.';
263
- couponMessage.style.color = 'red';
264
- });
265
- } else {
266
- couponMessage.innerText = 'Please enter a coupon code.';
267
- couponMessage.style.color = 'red';
 
 
 
268
  }
 
 
 
 
 
 
269
  }
270
-
271
- function proceedToOrder() {
272
- fetch('/checkout', {
 
 
 
 
 
 
 
273
  method: 'POST',
 
 
274
  })
275
  .then(response => response.json())
276
  .then(data => {
277
  if (data.success) {
278
- alert(data.message);
279
- window.location.href = '/order'; // Redirect to menu or order confirmation page
 
 
 
 
280
  } else {
281
- alert(data.error || data.message);
282
  }
283
  })
284
- .catch(err => console.error('Error during checkout:', err));
285
  }
286
- </script>
287
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
  </body>
289
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Your Cart</title>
 
7
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
8
  <style>
9
  body {
 
11
  background-color: #f8f9fa;
12
  }
13
  .cart-container {
14
+ max-width: 800px;
15
  margin: 20px auto;
16
  padding: 15px;
17
  background-color: #fff;
 
20
  }
21
  .cart-item {
22
  display: flex;
 
23
  justify-content: space-between;
24
+ align-items: center;
25
  border-bottom: 1px solid #dee2e6;
26
  padding: 10px 0;
27
  }
 
36
  margin-left: 15px;
37
  }
38
  .cart-item-title {
39
+ font-size: 1.1rem;
40
  font-weight: bold;
41
  }
42
  .cart-item-quantity {
43
  display: flex;
44
  align-items: center;
 
45
  }
46
  .cart-item-quantity button {
47
  width: 30px;
 
64
  text-align: right;
65
  margin-top: 15px;
66
  }
67
+ .coupon-section {
68
+ display: flex;
69
+ justify-content: space-between;
70
+ align-items: center;
71
+ margin-top: 20px;
72
+ }
73
+ .apply-button {
74
+ background-color: #28a745;
75
+ color: #fff;
76
+ padding: 5px 20px;
77
+ font-size: 1rem;
78
+ cursor: pointer;
79
+ border-radius: 5px;
80
+ }
81
+ .apply-button:disabled {
82
+ background-color: #6c757d;
83
+ }
84
  .checkout-button {
85
  background-color: #007bff;
86
  color: #fff;
87
  padding: 10px;
88
  border-radius: 5px;
 
89
  width: 100%;
90
  font-size: 1.2rem;
91
  cursor: pointer;
92
  margin-top: 10px;
93
  }
94
+ .error-message {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  color: red;
96
+ margin-top: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
98
  </style>
99
  </head>
100
  <body>
101
  <div class="container">
102
  <div class="cart-container">
103
+ <h3>Your Cart</h3>
104
+
 
 
 
 
105
  <!-- Cart Items -->
106
  {% for item in cart_items %}
107
  <div class="cart-item">
108
  <img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
109
  <div class="cart-item-details">
110
+ <div class="cart-item-title">{{ item.Name }}</div>
111
+ <div class="cart-item-quantity">
112
+ <button onclick="updateQuantity('decrease', '{{ item.Name }}')">-</button>
113
+ <input type="text" value="{{ item.Quantity__c }}" readonly>
114
+ <button onclick="updateQuantity('increase', '{{ item.Name }}')">+</button>
 
 
 
 
 
 
 
 
 
115
  </div>
116
  </div>
117
  <div class="cart-item-actions">
118
  <div class="text-primary">
119
+ $<span class="item-price">{{ item.Price__c }}</span>
120
  </div>
121
+ <button class="btn btn-danger btn-sm" onclick="removeItem('{{ item.Name }}')">Remove</button>
 
122
  </div>
123
  </div>
 
 
124
  {% endfor %}
125
 
126
+ <!-- Coupon Code Section -->
127
+ <div class="coupon-section">
128
+ <select id="couponCode" class="form-control" style="width: 70%;"></select>
129
+ <button class="apply-button" onclick="applyCoupon()">Apply Coupon</button>
 
 
130
  </div>
131
 
132
+ <div class="error-message" id="couponError"></div>
133
+
134
+ <!-- Cart Summary -->
135
  <div class="cart-summary">
136
+ <p><strong>Subtotal: </strong><span id="subtotal">${{ subtotal }}</span></p>
137
+ <p><strong>Discount: </strong><span id="discount">0.00</span></p>
138
+ <p><strong>Total: </strong><span id="total">$<span id="total-price">{{ total_price }}</span></span></p>
139
  </div>
 
140
 
141
+ <!-- Checkout Button -->
142
+ <button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
 
 
 
 
 
 
 
 
 
 
143
  </div>
144
  </div>
145
 
146
  <script>
147
+ // Fetch the coupon codes related to the logged-in user and populate the dropdown
148
  document.addEventListener("DOMContentLoaded", function() {
149
+ const customerEmail = "{{ customer_email }}"; // Assuming email is passed to the template
150
+
151
+ fetch(`/get_coupons/${customerEmail}`)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  .then(response => response.json())
153
  .then(data => {
154
  if (data.success) {
155
+ let couponDropdown = document.getElementById("couponCode");
156
+ data.coupons.forEach(coupon => {
157
+ let option = document.createElement("option");
158
+ option.value = coupon.Coupon_Code__c;
159
+ option.text = coupon.Coupon_Code__c;
160
+ couponDropdown.appendChild(option);
161
+ });
162
  } else {
163
+ document.getElementById('couponError').innerText = "No coupons available.";
 
164
  }
165
  })
166
+ .catch(error => console.error("Error fetching coupons:", error));
167
+ });
168
+
169
+ // Update item quantity
170
+ function updateQuantity(action, itemName) {
171
+ let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
172
+ let quantity = parseInt(quantityInput.value);
173
+ if (action === 'increase') {
174
+ quantity++;
175
+ } else if (action === 'decrease' && quantity > 1) {
176
+ quantity--;
177
  }
178
+ if (quantity < 1) {
179
+ quantity = 1;
180
+ }
181
+ quantityInput.value = quantity;
182
+ // Update price and subtotal
183
+ updateCart(itemName, quantity);
184
  }
185
+
186
+ // Apply coupon
187
+ function applyCoupon() {
188
+ let couponCode = document.getElementById('couponCode').value;
189
+ if (!couponCode) {
190
+ document.getElementById('couponError').innerText = "Please select a coupon.";
191
+ return;
192
+ }
193
+
194
+ fetch(`/apply_coupon`, {
195
  method: 'POST',
196
+ headers: { 'Content-Type': 'application/json' },
197
+ body: JSON.stringify({ coupon_code: couponCode })
198
  })
199
  .then(response => response.json())
200
  .then(data => {
201
  if (data.success) {
202
+ let discount = data.discount;
203
+ document.getElementById('discount').innerText = discount.toFixed(2);
204
+ let subtotal = parseFloat(document.getElementById('subtotal').innerText.replace('$', ''));
205
+ let total = subtotal - discount;
206
+ document.getElementById('total-price').innerText = total.toFixed(2);
207
+ document.getElementById('couponError').innerText = `Coupon applied! You saved $${discount.toFixed(2)}`;
208
  } else {
209
+ document.getElementById('couponError').innerText = "Invalid coupon code.";
210
  }
211
  })
212
+ .catch(error => console.error("Error applying coupon:", error));
213
  }
 
214
 
215
+ // Update the cart prices based on the quantity changes
216
+ function updateCart(itemName, quantity) {
217
+ let price = parseFloat(document.querySelector(`.item[data-item-name="${itemName}"] .item-price`).innerText.replace('$', ''));
218
+ let newPrice = price * quantity;
219
+ document.querySelector(`.item[data-item-name="${itemName}"] .item-price`).innerText = newPrice.toFixed(2);
220
+ // Update subtotal and total
221
+ let subtotal = 0;
222
+ document.querySelectorAll('.item').forEach(item => {
223
+ subtotal += parseFloat(item.querySelector('.item-price').innerText.replace('$', ''));
224
+ });
225
+ document.getElementById('subtotal').innerText = "$" + subtotal.toFixed(2);
226
+ let discount = parseFloat(document.getElementById('discount').innerText);
227
+ let total = subtotal - discount;
228
+ document.getElementById('total-price').innerText = total.toFixed(2);
229
+ }
230
+
231
+ // Proceed to the order summary page
232
+ function proceedToOrder() {
233
+ window.location.href = '/order_summary'; // Redirect to order summary page
234
+ }
235
+ </script>
236
  </body>
237
  </html>