Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +24 -22
templates/cart.html
CHANGED
@@ -157,29 +157,31 @@
|
|
157 |
<script>
|
158 |
// Fetch coupon codes automatically on page load
|
159 |
document.addEventListener("DOMContentLoaded", function () {
|
160 |
-
|
161 |
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
})
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
|
|
|
|
183 |
|
184 |
// Update quantity
|
185 |
function updateQuantity(action, itemName) {
|
|
|
157 |
<script>
|
158 |
// Fetch coupon codes automatically on page load
|
159 |
document.addEventListener("DOMContentLoaded", function () {
|
160 |
+
const customerEmail = "{{ customer_email }}"; // This should be rendered from the backend.
|
161 |
|
162 |
+
if (customerEmail) {
|
163 |
+
fetch('/get_coupon_codes', {
|
164 |
+
method: 'POST',
|
165 |
+
headers: { 'Content-Type': 'application/json' },
|
166 |
+
body: JSON.stringify({ email: customerEmail })
|
167 |
+
})
|
168 |
+
.then(response => response.json())
|
169 |
+
.then(data => {
|
170 |
+
if (data.success) {
|
171 |
+
const couponSelect = document.getElementById('coupon-code');
|
172 |
+
data.coupons.forEach(coupon => {
|
173 |
+
const option = document.createElement('option');
|
174 |
+
option.value = coupon.Coupon_Code__c;
|
175 |
+
option.textContent = coupon.Coupon_Code__c;
|
176 |
+
couponSelect.appendChild(option);
|
177 |
+
});
|
178 |
+
} else {
|
179 |
+
document.getElementById('coupon-message').innerText = data.message;
|
180 |
+
}
|
181 |
+
})
|
182 |
+
.catch(error => console.error('Error fetching coupon codes:', error));
|
183 |
+
}
|
184 |
+
});
|
185 |
|
186 |
// Update quantity
|
187 |
function updateQuantity(action, itemName) {
|