Spaces:
Sleeping
Sleeping
File size: 10,029 Bytes
c96d6aa 14c04be c96d6aa 14c04be c96d6aa 786415e 14c04be c96d6aa 14c04be c96d6aa 14c04be 8f9de7d 14c04be 8f9de7d 14c04be 8f9de7d 14c04be 8f9de7d c96d6aa 14c04be 786415e 14c04be 1cefdd1 c96d6aa 14c04be c96d6aa 14c04be b29184c 14c04be c96d6aa 14c04be c96d6aa 14c04be c96d6aa bd6ee74 8f9de7d bd6ee74 c96d6aa bd6ee74 786415e bd6ee74 14c04be bd6ee74 14c04be 786415e bd6ee74 786415e bd6ee74 14c04be 786415e 14c04be 786415e 14c04be bd6ee74 14c04be bd6ee74 9f54586 bd6ee74 9f54586 bd6ee74 9f54586 bd6ee74 9f54586 bd6ee74 14c04be bd6ee74 14c04be bd6ee74 14c04be bd6ee74 c96d6aa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Cart</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
}
.cart-container {
max-width: 800px;
margin: 20px auto;
padding: 15px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.cart-item {
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #dee2e6;
padding: 10px 0;
}
.cart-item img {
width: 70px;
height: 70px;
object-fit: cover;
border-radius: 5px;
}
.cart-item-details {
flex: 1;
margin-left: 15px;
}
.cart-item-title {
font-size: 1.1rem;
font-weight: bold;
}
.cart-item-quantity {
display: flex;
align-items: center;
}
.cart-item-quantity button {
width: 30px;
height: 30px;
border: none;
background-color: #f0f0f0;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
}
.cart-item-quantity input {
width: 40px;
text-align: center;
border: none;
background-color: #f8f9fa;
font-size: 1rem;
margin: 0 5px;
}
.cart-summary {
text-align: right;
margin-top: 15px;
}
.coupon-section {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 20px;
}
.apply-button {
background-color: #28a745;
color: #fff;
padding: 5px 20px;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
border-radius: 5px;
border: none;
transition: background-color 0.3s ease, transform 0.2s ease;
}
.apply-button:disabled {
background-color: #6c757d;
cursor: not-allowed;
}
.apply-button:hover {
background-color: #218838; /* Darker green on hover */
transform: scale(1.05); /* Slightly enlarge the button when hovered */
}
.checkout-button {
background-color: #007bff;
color: #fff;
padding: 10px;
border-radius: 5px;
width: 100%;
font-size: 1.2rem;
cursor: pointer;
margin-top: 10px;
}
.error-message {
color: red;
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container">
<div class="cart-container">
<h3>Your Cart</h3>
<!-- Cart Items -->
{% for item in cart_items %}
<div class="cart-item">
<img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
<div class="cart-item-details">
<div class="cart-item-title">{{ item.Name }}</div>
<div class="cart-item-addons">
<small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
</div>
<div class="cart-item-instructions">
<small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
</div>
<div class="cart-item-quantity">
<button onclick="updateQuantity('decrease', '{{ item.Name }}')">-</button>
<input type="text" value="{{ item.Quantity__c }}" readonly>
<button onclick="updateQuantity('increase', '{{ item.Name }}')">+</button>
</div>
</div>
<div class="cart-item-actions">
<div class="text-primary">
$<span class="item-price">{{ item.Price__c }}</span>
</div>
<button class="btn btn-danger btn-sm" onclick="removeItem('{{ item.Name }}')">Remove</button>
</div>
</div>
{% endfor %}
<div class="apply-coupon">
<label for="coupon-code">Coupon Code:</label>
<select id="coupon-code" name="coupon_code">
<option value="">Select a coupon code</option>
{% for coupon in coupon_codes %}
<option value="{{ coupon.Coupon_Code__c }}">{{ coupon.Coupon_Code__c }}</option>
{% endfor %}
</select>
<button type="button" class="apply-button" onclick="applyCoupon()">Apply Coupon</button>
<p id="coupon-message" class="coupon-message"></p>
</div>
<!-- Subtotal -->
<div class="cart-summary">
<p id="subtotal-text" class="fw-bold">Subtotal: ${{ subtotal }}</p>
<p id="discount-text" class="fw-bold">Discount: $0.00</p>
<p id="total-text" class="fw-bold">Total: ${{ subtotal }}</p> <!-- The final total after discount -->
<button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
</div>
<script>
// Fetch coupon codes automatically when the page loads
document.addEventListener("DOMContentLoaded", function() {
const customerEmail = "{{ customer_email }}"; // The email stored in the session
if (customerEmail) {
fetch(`/get_coupon_codes?email=${customerEmail}`)
.then(response => response.json())
.then(data => {
if (data.success && data.coupon_codes) {
const couponSelect = document.getElementById('coupon-code');
data.coupon_codes.forEach(coupon => {
const option = document.createElement('option');
option.value = coupon.Coupon_Code__c;
option.textContent = coupon.Coupon_Code__c;
couponSelect.appendChild(option);
});
} else {
document.getElementById('coupon-message').innerText = "No active coupons found for your account.";
document.getElementById('coupon-message').style.color = "red";
}
})
.catch(error => {
console.error('Error fetching coupon codes:', error);
});
}
});
// Update item quantity
function updateQuantity(action, itemName) {
let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
let quantity = parseInt(quantityInput.value);
if (action === 'increase') {
quantity++;
} else if (action === 'decrease' && quantity > 1) {
quantity--;
}
if (quantity < 1) {
quantity = 1;
}
quantityInput.value = quantity;
// Update price and subtotal
updateCart(itemName, quantity);
}
// Apply coupon and discount
function applyCoupon() {
const couponCode = document.getElementById('coupon-code').value;
const subtotal = parseFloat(document.getElementById('subtotal-text').innerText.replace('Subtotal: $', ''));
const couponMessage = document.getElementById('coupon-message');
if (couponCode) {
fetch('/apply_coupon', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ coupon_code: couponCode, subtotal: subtotal })
})
.then(response => response.json())
.then(data => {
if (data.success) {
const discount = data.discount;
const totalPrice = subtotal - discount;
document.getElementById('discount-text').innerText = `Discount: $${discount.toFixed(2)}`;
document.getElementById('total-text').innerText = `Total: $${totalPrice.toFixed(2)}`;
couponMessage.innerText = `Coupon applied! You saved $${discount.toFixed(2)}`;
couponMessage.style.color = 'green';
} else {
couponMessage.innerText = data.message;
couponMessage.style.color = 'red';
}
})
.catch(error => {
console.error('Error applying coupon:', error);
couponMessage.innerText = 'Error applying coupon.';
couponMessage.style.color = 'red';
});
} else {
couponMessage.innerText = 'Please select a coupon code.';
couponMessage.style.color = 'red';
}
}
function proceedToOrder() {
fetch('/checkout', {
method: 'POST',
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(data.message);
window.location.href = '/order'; // Redirect to menu or order confirmation page
} else {
alert(data.error || data.message);
}
})
.catch(err => console.error('Error during checkout:', err));
}
</script>
</body>
</html>
|