Rammohan0504 commited on
Commit
16fa40f
·
verified ·
1 Parent(s): 93dbe9c

Update templates/order_history.html

Browse files
Files changed (1) hide show
  1. 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
- fetch('/cart/add', {
117
- method: 'POST',
118
- headers: {
119
- 'Content-Type': 'application/json',
120
- },
121
- body: JSON.stringify({
122
- itemName: itemName, // Item to be reordered
123
- }),
124
- })
125
- .then(response => response.json())
126
- .then(data => {
127
- if (data.success) {
128
- alert('Item added to cart successfully!');
129
- } else {
130
- alert('Error: ' + data.error);
131
- }
132
- })
133
- .catch(error => {
134
- alert('An error occurred: ' + error);
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>