Rammohan0504 commited on
Commit
9f54586
·
verified ·
1 Parent(s): d3717de

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +92 -147
templates/cart.html CHANGED
@@ -1,159 +1,104 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
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>
 
1
+ <!-- Updated Apply Coupon Section -->
2
+ <div class="apply-coupon">
3
+ <label for="coupon-code">Coupon Code:</label>
4
+ <select id="coupon-code" name="coupon_code">
5
+ <option value="">Select a coupon code</option>
6
+ {% for coupon in coupon_codes %}
7
+ <option value="{{ coupon.Coupon_Code__c }}">{{ coupon.Coupon_Code__c }}</option>
8
+ {% endfor %}
9
+ </select>
10
+ <button type="button" onclick="applyCoupon()">Apply Coupon</button>
11
+ <p id="coupon-message" class="coupon-message"></p>
12
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ <!-- Subtotal -->
15
+ <div class="cart-summary">
16
+ <p id="subtotal-text" class="fw-bold">Subtotal: ${{ subtotal }}</p>
17
+ <p id="discount-text" class="fw-bold">Discount: $0.00</p>
18
+ <p id="total-text" class="fw-bold">Total: ${{ subtotal }}</p> <!-- The final total after discount -->
19
+ <button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
20
+ </div>
21
 
22
+ <script>
23
+ // Fetch coupon codes automatically when the page loads
24
+ document.addEventListener("DOMContentLoaded", function() {
25
+ const customerEmail = "{{ customer_email }}"; // The email stored in the session
26
 
27
+ if (customerEmail) {
28
+ fetch(`/get_coupon_codes?email=${customerEmail}`)
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  .then(response => response.json())
30
  .then(data => {
31
+ if (data.success && data.coupon_codes) {
32
+ const couponSelect = document.getElementById('coupon-code');
33
+ data.coupon_codes.forEach(coupon => {
34
+ const option = document.createElement('option');
35
+ option.value = coupon.Coupon_Code__c;
36
+ option.textContent = coupon.Coupon_Code__c;
37
+ couponSelect.appendChild(option);
38
+ });
39
  } else {
40
+ document.getElementById('coupon-message').innerText = "No active coupons found for your account.";
41
+ document.getElementById('coupon-message').style.color = "red";
42
  }
43
  })
44
  .catch(error => {
45
+ console.error('Error fetching coupon codes:', error);
 
46
  });
47
+ }
48
+ });
49
+
50
+ // Apply coupon and discount
51
+ function applyCoupon() {
52
+ const couponCode = document.getElementById('coupon-code').value;
53
+ const subtotal = parseFloat(document.getElementById('subtotal-text').innerText.replace('Subtotal: $', ''));
54
+ const couponMessage = document.getElementById('coupon-message');
55
+
56
+ if (couponCode) {
57
+ fetch('/apply_coupon', {
58
+ method: 'POST',
59
+ headers: {
60
+ 'Content-Type': 'application/json'
61
+ },
62
+ body: JSON.stringify({ coupon_code: couponCode, subtotal: subtotal })
63
+ })
64
+ .then(response => response.json())
65
+ .then(data => {
66
+ if (data.success) {
67
+ const discount = data.discount;
68
+ const totalPrice = subtotal - discount;
69
+ document.getElementById('discount-text').innerText = `Discount: $${discount.toFixed(2)}`;
70
+ document.getElementById('total-text').innerText = `Total: $${totalPrice.toFixed(2)}`;
71
+ couponMessage.innerText = `Coupon applied! You saved $${discount.toFixed(2)}`;
72
+ couponMessage.style.color = 'green';
73
+ } else {
74
+ couponMessage.innerText = data.message;
75
+ couponMessage.style.color = 'red';
76
+ }
77
+ })
78
+ .catch(error => {
79
+ console.error('Error applying coupon:', error);
80
+ couponMessage.innerText = 'Error applying coupon.';
81
+ couponMessage.style.color = 'red';
82
+ });
83
+ } else {
84
+ couponMessage.innerText = 'Please select a coupon code.';
85
+ couponMessage.style.color = 'red';
86
+ }
87
+ }
88
+
89
+ function proceedToOrder() {
90
+ fetch('/checkout', {
91
+ method: 'POST',
92
+ })
93
+ .then(response => response.json())
94
+ .then(data => {
95
+ if (data.success) {
96
+ alert(data.message);
97
+ window.location.href = '/order'; // Redirect to menu or order confirmation page
98
  } else {
99
+ alert(data.error || data.message);
100
  }
101
+ })
102
+ .catch(err => console.error('Error during checkout:', err));
103
+ }
104
+ </script>