From b66e2620264af6667456dbcb0cd074bddd04a701 Mon Sep 17 00:00:00 2001
From: 65160381 <65160381@go.buu.ac.th>
Date: Tue, 25 Mar 2025 04:33:58 +0700
Subject: [PATCH] 10.2

---
 public/edit-order.html | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/public/edit-order.html b/public/edit-order.html
index f4ed37f..012d668 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>
-- 
GitLab