Rammohan0504 commited on
Commit
33ec344
·
verified ·
1 Parent(s): b5479ce

Update templates/order_history.html

Browse files
Files changed (1) hide show
  1. templates/order_history.html +47 -32
templates/order_history.html CHANGED
@@ -114,39 +114,54 @@
114
 
115
  <script>
116
  function addToCart(itemName) {
117
- // Get the price from the button's data-price attribute
118
- const itemPrice = document.getElementById(itemName).dataset.price;
119
-
120
- if (!itemPrice) {
121
- alert('Price is missing for the item');
122
- return;
123
- }
124
-
125
- // Ensure the price is treated as a string
126
- const itemPriceStr = String(itemPrice); // Explicitly convert to string
127
-
128
- fetch('/cart/add', {
129
- method: 'POST',
130
- headers: {
131
- 'Content-Type': 'application/json',
132
- },
133
- body: JSON.stringify({
134
- itemName: itemName, // Item name to be reordered
135
- itemPrice: itemPriceStr, // Pass the price as a string
136
- }),
137
- })
138
- .then(response => response.json())
139
- .then(data => {
140
- if (data.success) {
141
- alert('Item added to cart successfully!');
142
- } else {
143
- alert('Error: ' + data.error);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  }
145
- })
146
- .catch(error => {
147
- alert('An error occurred: ' + error);
148
- });
149
- }
150
  </script>
151
 
152
  </body>
 
114
 
115
  <script>
116
  function addToCart(itemName) {
117
+ // Get the price from the button's data-price attribute
118
+ const itemPrice = document.getElementById(itemName).dataset.price;
119
+ const itemImage = document.getElementById(itemName).dataset.image; // Get image URL
120
+ const category = document.getElementById(itemName).dataset.category; // Get item category
121
+ const section = document.getElementById(itemName).dataset.section; // Get item section
122
+ const addons = []; // This could be an array of selected addons
123
+ const instructions = ""; // This could be user-provided instructions for the item
124
+
125
+ if (!itemPrice || !itemImage || !itemName || !category || !section) {
126
+ alert('Missing required item data.');
127
+ return;
128
+ }
129
+
130
+ // Ensure the price is explicitly treated as a string
131
+ const itemPriceStr = String(itemPrice); // Explicitly convert to string
132
+
133
+ // Create a JSON object to send to the server
134
+ const dataToSend = {
135
+ itemName: itemName, // Item name to be reordered
136
+ itemPrice: itemPriceStr, // Price as a string
137
+ itemImage: itemImage, // Image URL of the item
138
+ addons: addons, // List of add-ons (empty for now, can be dynamically populated)
139
+ instructions: instructions, // Instructions for the item (empty for now)
140
+ category: category, // Category of the item
141
+ section: section // Section of the item
142
+ };
143
+
144
+ // Send the data to the server via a POST request
145
+ fetch('/cart/add', {
146
+ method: 'POST',
147
+ headers: {
148
+ 'Content-Type': 'application/json',
149
+ },
150
+ body: JSON.stringify(dataToSend),
151
+ })
152
+ .then(response => response.json())
153
+ .then(data => {
154
+ if (data.success) {
155
+ alert('Item added to cart successfully!');
156
+ } else {
157
+ alert('Error: ' + data.error);
158
+ }
159
+ })
160
+ .catch(error => {
161
+ alert('An error occurred: ' + error);
162
+ });
163
  }
164
+
 
 
 
 
165
  </script>
166
 
167
  </body>