Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +21 -13
templates/cart.html
CHANGED
@@ -81,10 +81,8 @@
|
|
81 |
margin-top: 20px;
|
82 |
text-align: right;
|
83 |
}
|
84 |
-
.apply-coupon
|
85 |
-
|
86 |
-
padding: 5px;
|
87 |
-
margin-right: 10px;
|
88 |
}
|
89 |
.apply-coupon button {
|
90 |
background-color: #28a745;
|
@@ -92,7 +90,6 @@
|
|
92 |
padding: 5px 15px;
|
93 |
border: none;
|
94 |
cursor: pointer;
|
95 |
-
font-size: 1rem;
|
96 |
}
|
97 |
.apply-coupon button:hover {
|
98 |
background-color: #218838;
|
@@ -149,7 +146,12 @@
|
|
149 |
<!-- Apply Coupon Section -->
|
150 |
<div class="apply-coupon">
|
151 |
<label for="coupon-code">Coupon Code:</label>
|
152 |
-
<
|
|
|
|
|
|
|
|
|
|
|
153 |
<button type="button" onclick="applyCoupon()">Apply Coupon</button>
|
154 |
<p id="coupon-message" class="coupon-message"></p>
|
155 |
</div>
|
@@ -163,23 +165,29 @@
|
|
163 |
</div>
|
164 |
|
165 |
<script>
|
166 |
-
// Fetch coupon
|
167 |
document.addEventListener("DOMContentLoaded", function() {
|
168 |
const customerEmail = "{{ customer_email }}"; // The email stored in the session
|
169 |
|
170 |
if (customerEmail) {
|
171 |
-
fetch(`/
|
172 |
.then(response => response.json())
|
173 |
.then(data => {
|
174 |
-
if (data.success && data.
|
175 |
-
document.getElementById('coupon-code')
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
} else {
|
177 |
-
document.getElementById('coupon-message').innerText = "No
|
178 |
document.getElementById('coupon-message').style.color = "red";
|
179 |
}
|
180 |
})
|
181 |
.catch(error => {
|
182 |
-
console.error('Error fetching coupon
|
183 |
});
|
184 |
}
|
185 |
});
|
@@ -218,7 +226,7 @@
|
|
218 |
couponMessage.style.color = 'red';
|
219 |
});
|
220 |
} else {
|
221 |
-
couponMessage.innerText = 'Please
|
222 |
couponMessage.style.color = 'red';
|
223 |
}
|
224 |
}
|
|
|
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;
|
|
|
90 |
padding: 5px 15px;
|
91 |
border: none;
|
92 |
cursor: pointer;
|
|
|
93 |
}
|
94 |
.apply-coupon button:hover {
|
95 |
background-color: #218838;
|
|
|
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>
|
|
|
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 |
});
|
|
|
226 |
couponMessage.style.color = 'red';
|
227 |
});
|
228 |
} else {
|
229 |
+
couponMessage.innerText = 'Please select a coupon code.';
|
230 |
couponMessage.style.color = 'red';
|
231 |
}
|
232 |
}
|