Rammohan0504 commited on
Commit
a461574
·
verified ·
1 Parent(s): 55390a4

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. 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
- const customerEmail = "{{ customer_email }}";
161
 
162
- fetch('/get_coupon_codes', {
163
- method: 'POST',
164
- headers: { 'Content-Type': 'application/json' },
165
- body: JSON.stringify({ email: customerEmail })
166
- })
167
- .then(response => response.json())
168
- .then(data => {
169
- if (data.success) {
170
- const couponSelect = document.getElementById('coupon-code');
171
- data.coupons.forEach(coupon => {
172
- const option = document.createElement('option');
173
- option.value = coupon.Coupon_Code__c;
174
- option.textContent = coupon.Coupon_Code__c;
175
- couponSelect.appendChild(option);
176
- });
177
- } else {
178
- document.getElementById('coupon-message').innerText = "No active coupons found.";
179
- }
180
- })
181
- .catch(err => console.error('Error fetching coupons:', err));
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) {