diff --git a/public/edit-order.html b/public/edit-order.html index f4ed37fe2b211f635e121cd092e4c51cfd62cd34..012d6688e40142dba329c1a78fd61aae1cfef784 100644 --- a/public/edit-order.html +++ b/public/edit-order.html @@ -57,7 +57,10 @@ <label for="order-products">Products:</label> <ul id="order-products"> ${order.products.map(product => ` - <li>${product.name} - $${product.price} x ${product.quantity}</li> + <li> + ${product.name} - $${product.price} x ${product.quantity} + <input type="number" value="${product.quantity}" min="1" id="product-quantity-${product.id}" /> + </li> `).join('')} </ul> </div> @@ -81,6 +84,15 @@ const status = document.getElementById('order-status').value; const shippingAddress = document.getElementById('order-shipping-address').value; + // Get updated quantities of each product + const updatedProducts = []; + const productsList = document.querySelectorAll('#order-products li'); + productsList.forEach(productItem => { + const productId = productItem.dataset.productId; + const quantity = document.getElementById(`product-quantity-${productId}`).value; + updatedProducts.push({ productId, quantity }); + }); + try { const response = await fetch(`/api/orders/${orderId}`, { method: 'PUT', @@ -89,7 +101,8 @@ }, body: JSON.stringify({ status: status, - shipping_address: shippingAddress + shipping_address: shippingAddress, + products: updatedProducts }) }); @@ -109,5 +122,6 @@ // Load order details when page loads window.onload = loadOrderDetails; </script> + </body> </html>