Spaces:
Sleeping
Sleeping
Update templates/order_history.html
Browse files- templates/order_history.html +30 -20
templates/order_history.html
CHANGED
@@ -113,27 +113,37 @@
|
|
113 |
<script>
|
114 |
// Function to handle reordering an item
|
115 |
function addToCart(itemName) {
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
136 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
</script>
|
138 |
|
139 |
</body>
|
|
|
113 |
<script>
|
114 |
// Function to handle reordering an item
|
115 |
function addToCart(itemName) {
|
116 |
+
// Assuming the price is available in the item details
|
117 |
+
const itemPrice = document.getElementById(itemName).dataset.price; // You could store the price as a data attribute
|
118 |
+
|
119 |
+
if (!itemPrice) {
|
120 |
+
alert('Price is missing for the item');
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
|
124 |
+
fetch('/cart/add', {
|
125 |
+
method: 'POST',
|
126 |
+
headers: {
|
127 |
+
'Content-Type': 'application/json',
|
128 |
+
},
|
129 |
+
body: JSON.stringify({
|
130 |
+
itemName: itemName, // Item to be reordered
|
131 |
+
itemPrice: itemPrice, // Pass the price
|
132 |
+
}),
|
133 |
+
})
|
134 |
+
.then(response => response.json())
|
135 |
+
.then(data => {
|
136 |
+
if (data.success) {
|
137 |
+
alert('Item added to cart successfully!');
|
138 |
+
} else {
|
139 |
+
alert('Error: ' + data.error);
|
140 |
}
|
141 |
+
})
|
142 |
+
.catch(error => {
|
143 |
+
alert('An error occurred: ' + error);
|
144 |
+
});
|
145 |
+
}
|
146 |
+
|
147 |
</script>
|
148 |
|
149 |
</body>
|