Spaces:
Sleeping
Sleeping
Update templates/order_history.html
Browse files- templates/order_history.html +47 -32
templates/order_history.html
CHANGED
@@ -114,39 +114,54 @@
|
|
114 |
|
115 |
<script>
|
116 |
function addToCart(itemName) {
|
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 |
-
.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>
|