Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +9 -11
templates/cart.html
CHANGED
@@ -171,31 +171,31 @@
|
|
171 |
|
172 |
<script>
|
173 |
// Example function to handle the increase/decrease button clicks
|
174 |
-
function updateQuantity(itemName,
|
175 |
-
|
176 |
-
|
177 |
if (action === 'increase') {
|
178 |
quantity++;
|
179 |
} else if (action === 'decrease' && quantity > 1) {
|
180 |
quantity--;
|
181 |
}
|
182 |
-
// Send
|
183 |
fetch('/cart/update_quantity', {
|
184 |
method: 'POST',
|
185 |
headers: {
|
186 |
'Content-Type': 'application/json',
|
187 |
},
|
188 |
body: JSON.stringify({
|
189 |
-
email: email
|
190 |
-
item_name: itemName,
|
191 |
-
quantity: quantity
|
192 |
})
|
193 |
})
|
194 |
.then(response => response.json())
|
195 |
.then(data => {
|
196 |
if (data.success) {
|
197 |
-
// Update the
|
198 |
-
document.
|
199 |
} else {
|
200 |
alert("Error updating quantity: " + data.error);
|
201 |
}
|
@@ -205,8 +205,6 @@
|
|
205 |
});
|
206 |
}
|
207 |
|
208 |
-
|
209 |
-
|
210 |
function calculateSubtotal() {
|
211 |
let subtotal = 0;
|
212 |
document.querySelectorAll('.cart-item').forEach(item => {
|
|
|
171 |
|
172 |
<script>
|
173 |
// Example function to handle the increase/decrease button clicks
|
174 |
+
function updateQuantity(action, itemName, customerEmail) {
|
175 |
+
let quantity = parseInt(document.querySelector(`input[data-item-name="${itemName}"]`).value); // Get current quantity
|
176 |
+
// Update quantity based on action
|
177 |
if (action === 'increase') {
|
178 |
quantity++;
|
179 |
} else if (action === 'decrease' && quantity > 1) {
|
180 |
quantity--;
|
181 |
}
|
182 |
+
// Send updated quantity to the server
|
183 |
fetch('/cart/update_quantity', {
|
184 |
method: 'POST',
|
185 |
headers: {
|
186 |
'Content-Type': 'application/json',
|
187 |
},
|
188 |
body: JSON.stringify({
|
189 |
+
email: customerEmail, // Customer's email
|
190 |
+
item_name: itemName, // Item name
|
191 |
+
quantity: quantity // New quantity
|
192 |
})
|
193 |
})
|
194 |
.then(response => response.json())
|
195 |
.then(data => {
|
196 |
if (data.success) {
|
197 |
+
// Update the quantity in the UI
|
198 |
+
document.querySelector(`input[data-item-name="${itemName}"]`).value = quantity;
|
199 |
} else {
|
200 |
alert("Error updating quantity: " + data.error);
|
201 |
}
|
|
|
205 |
});
|
206 |
}
|
207 |
|
|
|
|
|
208 |
function calculateSubtotal() {
|
209 |
let subtotal = 0;
|
210 |
document.querySelectorAll('.cart-item').forEach(item => {
|