Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +27 -37
templates/cart.html
CHANGED
@@ -183,43 +183,33 @@
|
|
183 |
}
|
184 |
});
|
185 |
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
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) {
|