diff --git a/shop-routes/order.js b/shop-routes/order.js
index 548028ea054ff8255d35645369249d043acacc1d..c314cb4005f6265c563062994856672afe2c1108 100644
--- a/shop-routes/order.js
+++ b/shop-routes/order.js
@@ -46,8 +46,8 @@ router.get('/history', isAuthenticated, async (req, res) => {
 router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
     try {
         const { orderId } = req.params;
+        console.log(`Fetching order details for order ID: ${orderId}, Session ID: ${req.session.id}`);
 
-        // ดึงข้อมูลออเดอร์
         const [orderResults] = await pool.query(
             `SELECT id, total_amount, status, shipping_address, created_at 
              FROM orders WHERE id = ? AND session_id = ?`, 
@@ -55,12 +55,12 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
         );
 
         if (orderResults.length === 0) {
-            return res.status(404).send("ไม่พบคำสั่งซื้อ หรือไม่มีสิทธิ์เข้าถึง");
+            console.log("Order not found or user has no permission.");
+            return res.status(404).json({ message: "ไม่พบคำสั่งซื้อ หรือไม่มีสิทธิ์เข้าถึง" });
         }
 
         const order = orderResults[0];
-
-        // ดึงรายการสินค้าในออเดอร์
+        
         const [items] = await pool.query(
             `SELECT products.name, products.image_url, order_items.quantity, order_items.price
              FROM order_items
@@ -71,8 +71,8 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
 
         res.render('order-detail', { order, items });
     } catch (error) {
-        console.error(error);
-        res.status(500).send('เกิดข้อผิดพลาดในการโหลดรายละเอียดคำสั่งซื้อ');
+        console.error("ERROR fetching order details:", error); // ดู Error Log
+        res.status(500).json({ message: "Something went wrong.", error: error.message });
     }
 });