Rammohan0504 commited on
Commit
f952b3c
·
verified ·
1 Parent(s): a96d0b4

Update templates/order_history.html

Browse files
Files changed (1) hide show
  1. templates/order_history.html +33 -31
templates/order_history.html CHANGED
@@ -115,39 +115,41 @@
115
  </footer>
116
 
117
  <script>
118
- // Function to handle reordering an item
119
  function addToCart(itemName) {
120
- // Assuming the price is available in the item details
121
- const itemPrice = document.getElementById(itemName).dataset.price; // You could store the price as a data attribute
122
-
123
- if (!itemPrice) {
124
- alert('Price is missing for the item');
125
- return;
126
- }
127
-
128
- fetch('/cart/add', {
129
- method: 'POST',
130
- headers: {
131
- 'Content-Type': 'application/json',
132
- },
133
- body: JSON.stringify({
134
- itemName: itemName, // Item to be reordered
135
- itemPrice: itemPrice, // Pass the price
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
-
151
  </script>
152
 
153
  </body>
 
115
  </footer>
116
 
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 = itemPrice.toString();
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>