Update templates/order_history.html
Browse files- templates/order_history.html +32 -32
templates/order_history.html
CHANGED
@@ -117,39 +117,39 @@
|
|
117 |
<script>
|
118 |
function addToCart(itemName) {
|
119 |
// Get the price from the button's data-price attribute
|
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 |
-
}
|
147 |
-
})
|
148 |
-
.catch(error => {
|
149 |
-
alert('An error occurred: ' + error);
|
150 |
-
});
|
151 |
}
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
</script>
|
154 |
|
155 |
</body>
|
|
|
117 |
<script>
|
118 |
function addToCart(itemName) {
|
119 |
// Get the price from the button's data-price attribute
|
120 |
+
const itemPrice = document.getElementById(itemName).dataset.price; // This is fetched as a string
|
121 |
+
|
122 |
+
if (!itemPrice) {
|
123 |
+
alert('Price is missing for the item');
|
124 |
+
return;
|
125 |
+
}
|
126 |
+
|
127 |
+
// Ensure the price is a string
|
128 |
+
const itemPriceStr = String(itemPrice); // Ensure it's explicitly converted to a string
|
129 |
+
|
130 |
+
fetch('/cart/add', {
|
131 |
+
method: 'POST',
|
132 |
+
headers: {
|
133 |
+
'Content-Type': 'application/json',
|
134 |
+
},
|
135 |
+
body: JSON.stringify({
|
136 |
+
itemName: itemName, // Item name to be reordered
|
137 |
+
itemPrice: itemPriceStr, // Pass the price as a string
|
138 |
+
}),
|
139 |
+
})
|
140 |
+
.then(response => response.json())
|
141 |
+
.then(data => {
|
142 |
+
if (data.success) {
|
143 |
+
alert('Item added to cart successfully!');
|
144 |
+
} else {
|
145 |
+
alert('Error: ' + data.error);
|
|
|
|
|
|
|
|
|
|
|
146 |
}
|
147 |
+
})
|
148 |
+
.catch(error => {
|
149 |
+
alert('An error occurred: ' + error);
|
150 |
+
});
|
151 |
+
}
|
152 |
+
|
153 |
</script>
|
154 |
|
155 |
</body>
|