Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit bf3e439e authored by 65160270's avatar 65160270
Browse files

update-cart

parent a3092bff
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@ router.get('/', async (req, res) => {
}
});
// เพิ่มสินค้าลงตะกร้า
// เพิ่มสินค้าลงตะกร้า
router.post('/add', async (req, res) => {
const { productId, quantity } = req.body;
......@@ -50,8 +51,8 @@ router.post('/add', async (req, res) => {
// ตรวจสอบว่าสินค้านี้มีอยู่ในตะกร้าหรือยัง
const [[existingItem]] = await pool.query(
'SELECT id, quantity FROM cart_items WHERE user_id = ? AND product_id = ?',
[req.session.user.id, productId] // ใช้ user_id แทน session_id
'SELECT id, quantity FROM cart_items WHERE session_id = ? AND product_id = ?',
[req.session.user.id, productId]
);
if (existingItem) {
......@@ -67,8 +68,8 @@ router.post('/add', async (req, res) => {
} else {
// เพิ่มสินค้าใหม่
await pool.query(
'INSERT INTO cart_items (user_id, product_id, quantity) VALUES (?, ?, ?)',
[req.session.user.id, productId, parseInt(quantity)] // เปลี่ยน session_id → user_id
'INSERT INTO cart_items (session_id, product_id, quantity) VALUES (?, ?, ?)',
[req.session.id, productId, parseInt(quantity)]
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment