Rammohan0504 commited on
Commit
201f229
·
verified ·
1 Parent(s): 65202a1

Update templates/order_history.html

Browse files
Files changed (1) hide show
  1. templates/order_history.html +46 -46
templates/order_history.html CHANGED
@@ -100,7 +100,7 @@
100
  id="{{ item_parts[0].strip() }}"
101
  data-price="{{ item_parts[3].strip().replace('Price:', '') }}"
102
  data-image="{{ item_parts[4].strip().replace('Image:', '') }}"
103
- data-category="Main Course" <!-- Example category --> >
104
  Reorder
105
  </button>
106
 
@@ -120,52 +120,52 @@
120
 
121
  <script>
122
  function addToCart(itemName) {
123
- // Get the price, image, category, and section from the button's data- attributes
124
- const button = document.getElementById(itemName); // Get the button element
125
- const itemPrice = button.dataset.price; // Get price from data-price attribute
126
- const itemImage = button.dataset.image; // Get image from data-image attribute
127
- const category = button.dataset.category; // Get category from data-category attribute
128
- const section = button.dataset.section; // Get section from data-section attribute
129
-
130
- if (!itemPrice || !itemImage || !itemName || !category || !section) {
131
- alert('Missing required item data.');
132
- return;
133
- }
134
-
135
- // Ensure the price is explicitly treated as a string
136
- const itemPriceStr = String(itemPrice); // Convert price to string
137
-
138
- // Create a JSON object to send to the server
139
- const dataToSend = {
140
- itemName: itemName, // Item name to be reordered
141
- itemPrice: itemPriceStr, // Price as a string
142
- itemImage: itemImage, // Image URL of the item
143
- addons: [], // List of add-ons (empty for now)
144
- instructions: "", // Instructions for the item (empty for now)
145
- category: category, // Category of the item
146
- section: section // Section of the item
147
- };
148
-
149
- // Send the data to the server via a POST request
150
- fetch('/cart/add', {
151
- method: 'POST',
152
- headers: {
153
- 'Content-Type': 'application/json',
154
- },
155
- body: JSON.stringify(dataToSend),
156
- })
157
- .then(response => response.json())
158
- .then(data => {
159
- if (data.success) {
160
- alert('Item added to cart successfully!');
161
- } else {
162
- alert('Error: ' + data.error);
163
- }
164
- })
165
- .catch(error => {
166
- alert('An error occurred: ' + error);
167
- });
168
  }
 
 
 
 
 
 
169
  </script>
170
 
171
  </body>
 
100
  id="{{ item_parts[0].strip() }}"
101
  data-price="{{ item_parts[3].strip().replace('Price:', '') }}"
102
  data-image="{{ item_parts[4].strip().replace('Image:', '') }}"
103
+ data-category="Main Course" <!-- Example category -->
104
  Reorder
105
  </button>
106
 
 
120
 
121
  <script>
122
  function addToCart(itemName) {
123
+ const button = document.getElementById(itemName); // Get the button element by its ID
124
+ const itemPrice = button.dataset.price; // Get price from data-price attribute
125
+ const itemImage = button.dataset.image; // Get image URL from data-image attribute
126
+ const category = button.dataset.category; // Get category from data-category attribute
127
+ const section = button.dataset.section; // Get section from data-section attribute
128
+
129
+ if (!itemPrice || !itemImage || !itemName || !category || !section) {
130
+ alert('Missing required item data.');
131
+ return;
132
+ }
133
+
134
+ // Ensure the price is explicitly treated as a string
135
+ const itemPriceStr = String(itemPrice); // Explicitly convert to string
136
+
137
+ // Create a JSON object to send to the server
138
+ const dataToSend = {
139
+ itemName: itemName, // Item name to be reordered
140
+ itemPrice: itemPriceStr, // Price as a string
141
+ itemImage: itemImage, // Image URL of the item
142
+ addons: [], // List of add-ons (empty for now)
143
+ instructions: "", // Instructions for the item (empty for now)
144
+ category: category, // Category of the item
145
+ section: section // Section of the item
146
+ };
147
+
148
+ // Send the data to the server via a POST request
149
+ fetch('/cart/add', {
150
+ method: 'POST',
151
+ headers: {
152
+ 'Content-Type': 'application/json',
153
+ },
154
+ body: JSON.stringify(dataToSend),
155
+ })
156
+ .then(response => response.json())
157
+ .then(data => {
158
+ if (data.success) {
159
+ alert('Item added to cart successfully!');
160
+ } else {
161
+ alert('Error: ' + data.error);
 
 
 
 
 
 
162
  }
163
+ })
164
+ .catch(error => {
165
+ alert('An error occurred: ' + error);
166
+ });
167
+ }
168
+
169
  </script>
170
 
171
  </body>