Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +97 -191
templates/cart.html
CHANGED
@@ -3,251 +3,157 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<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 |
-
.
|
15 |
max-width: 768px;
|
16 |
margin: 20px auto;
|
17 |
-
padding:
|
18 |
background-color: #fff;
|
19 |
border-radius: 10px;
|
20 |
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
|
|
21 |
}
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
justify-content: space-between;
|
26 |
-
border-bottom: 1px solid #dee2e6;
|
27 |
-
padding: 10px 0;
|
28 |
}
|
29 |
-
.
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
border-radius: 5px;
|
34 |
}
|
35 |
-
.
|
36 |
-
|
37 |
-
margin-left: 15px;
|
38 |
}
|
39 |
-
.
|
|
|
|
|
40 |
font-size: 1rem;
|
41 |
-
|
42 |
}
|
43 |
-
.
|
44 |
-
|
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 |
-
.
|
70 |
-
|
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
|
|
|
|
|
85 |
font-size: 1rem;
|
|
|
86 |
}
|
87 |
-
.apply-coupon button {
|
|
|
88 |
background-color: #28a745;
|
89 |
color: white;
|
90 |
-
|
91 |
border: none;
|
|
|
92 |
cursor: pointer;
|
93 |
}
|
94 |
-
.apply-coupon button:hover {
|
95 |
background-color: #218838;
|
96 |
}
|
97 |
-
.
|
98 |
-
margin-top:
|
|
|
|
|
|
|
99 |
font-size: 1rem;
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
</style>
|
103 |
</head>
|
104 |
<body>
|
105 |
-
<div class="container">
|
106 |
-
<
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
</div>
|
110 |
-
|
111 |
-
|
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 |
-
|
147 |
-
|
148 |
-
<
|
149 |
-
<option value="">Select a coupon code</option>
|
150 |
-
{% for coupon in coupon_codes %}
|
151 |
-
<option value="{{ coupon.Coupon_Code__c }}">{{ coupon.Coupon_Code__c }}</option>
|
152 |
-
{% endfor %}
|
153 |
-
</select>
|
154 |
-
<button type="button" onclick="applyCoupon()">Apply Coupon</button>
|
155 |
-
<p id="coupon-message" class="coupon-message"></p>
|
156 |
</div>
|
157 |
|
158 |
-
<!--
|
159 |
-
<div class="
|
160 |
-
|
161 |
-
<p id="discount-text" class="fw-bold">Discount: $0.00</p>
|
162 |
-
<p id="total-text" class="fw-bold">Total: ${{ subtotal }}</p> <!-- The final total after discount -->
|
163 |
-
<button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
|
164 |
</div>
|
165 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
</div>
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
172 |
|
173 |
-
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
.then(response => response.json())
|
176 |
.then(data => {
|
177 |
-
if (data.success
|
178 |
-
|
179 |
-
data.
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
});
|
185 |
} else {
|
186 |
-
|
187 |
-
document.getElementById('coupon-message').style.color = "red";
|
188 |
}
|
189 |
})
|
190 |
.catch(error => {
|
191 |
-
console.error('Error
|
|
|
192 |
});
|
193 |
-
}
|
194 |
-
});
|
195 |
-
|
196 |
-
// Apply coupon and discount
|
197 |
-
function applyCoupon() {
|
198 |
-
const couponCode = document.getElementById('coupon-code').value;
|
199 |
-
const subtotal = parseFloat(document.getElementById('subtotal-text').innerText.replace('Subtotal: $', ''));
|
200 |
-
const couponMessage = document.getElementById('coupon-message');
|
201 |
-
|
202 |
-
if (couponCode) {
|
203 |
-
fetch('/apply_coupon', {
|
204 |
-
method: 'POST',
|
205 |
-
headers: {
|
206 |
-
'Content-Type': 'application/json'
|
207 |
-
},
|
208 |
-
body: JSON.stringify({ coupon_code: couponCode, subtotal: subtotal })
|
209 |
-
})
|
210 |
-
.then(response => response.json())
|
211 |
-
.then(data => {
|
212 |
-
if (data.success) {
|
213 |
-
const discount = data.discount;
|
214 |
-
const totalPrice = subtotal - discount;
|
215 |
-
document.getElementById('discount-text').innerText = `Discount: $${discount.toFixed(2)}`;
|
216 |
-
document.getElementById('total-text').innerText = `Total: $${totalPrice.toFixed(2)}`;
|
217 |
-
couponMessage.innerText = `Coupon applied! You saved $${discount.toFixed(2)}`;
|
218 |
-
couponMessage.style.color = 'green';
|
219 |
-
} else {
|
220 |
-
couponMessage.innerText = data.message;
|
221 |
-
couponMessage.style.color = 'red';
|
222 |
-
}
|
223 |
-
})
|
224 |
-
.catch(error => {
|
225 |
-
console.error('Error applying coupon:', error);
|
226 |
-
couponMessage.innerText = 'Error applying coupon.';
|
227 |
-
couponMessage.style.color = 'red';
|
228 |
-
});
|
229 |
-
} else {
|
230 |
-
couponMessage.innerText = 'Please select a coupon code.';
|
231 |
-
couponMessage.style.color = 'red';
|
232 |
-
}
|
233 |
-
}
|
234 |
-
|
235 |
-
function proceedToOrder() {
|
236 |
-
fetch('/checkout', {
|
237 |
-
method: 'POST',
|
238 |
-
})
|
239 |
-
.then(response => response.json())
|
240 |
-
.then(data => {
|
241 |
-
if (data.success) {
|
242 |
-
alert(data.message);
|
243 |
-
window.location.href = '/order'; // Redirect to menu or order confirmation page
|
244 |
} else {
|
245 |
-
alert(
|
246 |
}
|
247 |
-
}
|
248 |
-
|
249 |
-
}
|
250 |
-
</script>
|
251 |
-
|
252 |
</body>
|
253 |
</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', {
|
130 |
+
method: 'POST',
|
131 |
+
headers: {
|
132 |
+
'Content-Type': 'application/json'
|
133 |
+
},
|
134 |
+
body: JSON.stringify({ coupon_code: couponCode, subtotal: subtotal })
|
135 |
+
})
|
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>
|