Rammohan0504 commited on
Commit
9ad3095
·
verified ·
1 Parent(s): 4340133

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +27 -37
templates/cart.html CHANGED
@@ -183,43 +183,33 @@
183
  }
184
  });
185
 
186
- function updateQuantity(action, itemName) {
187
- let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
188
- let quantity = parseInt(quantityInput.value);
189
-
190
- if (action === 'increase') {
191
- quantity++;
192
- } else if (action === 'decrease' && quantity > 1) {
193
- quantity--;
194
- }
195
-
196
- // Ensure quantity is valid
197
- if (isNaN(quantity) || quantity < 1) {
198
- alert("Invalid quantity!");
199
- return;
200
- }
201
-
202
- fetch('/cart/update_quantity', {
203
- method: 'POST',
204
- headers: {
205
- 'Content-Type': 'application/json'
206
- },
207
- body: JSON.stringify({
208
- item_name: itemName,
209
- quantity: quantity
210
- })
211
- })
212
- .then(response => response.json())
213
- .then(data => {
214
- if (data.success) {
215
- quantityInput.value = quantity;
216
- location.reload();
217
- } else {
218
- alert("Error updating quantity: " + (data.message || "Unknown error"));
219
- }
220
- })
221
- .catch(err => console.error("Error:", err));
222
- }
223
 
224
  // Remove item
225
  function removeItemFromCart(itemName) {
 
183
  }
184
  });
185
 
186
+ // Update quantity
187
+ function updateQuantity(action, itemName) {
188
+ const quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
189
+ let quantity = parseInt(quantityInput.value);
190
+
191
+ if (action === 'increase') {
192
+ quantity++;
193
+ } else if (action === 'decrease' && quantity > 1) {
194
+ quantity--;
195
+ }
196
+
197
+ fetch('/cart/update_quantity', {
198
+ method: 'POST',
199
+ headers: { 'Content-Type': 'application/json' },
200
+ body: JSON.stringify({ item_name: itemName, quantity: quantity })
201
+ })
202
+ .then(response => response.json())
203
+ .then(data => {
204
+ if (data.success) {
205
+ quantityInput.value = quantity;
206
+ location.reload();
207
+ } else {
208
+ alert('Error updating quantity: ' + data.message);
209
+ }
210
+ })
211
+ .catch(err => console.error('Error:', err));
212
+ }
 
 
 
 
 
 
 
 
 
 
213
 
214
  // Remove item
215
  function removeItemFromCart(itemName) {