Gitlab@Informatics

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

update-cart

parent 58df9a63
No related branches found
No related tags found
No related merge requests found
...@@ -88,8 +88,8 @@ router.post('/update', async (req, res) => { ...@@ -88,8 +88,8 @@ router.post('/update', async (req, res) => {
`SELECT cart_items.*, products.price, products.stock `SELECT cart_items.*, products.price, products.stock
FROM cart_items FROM cart_items
JOIN products ON cart_items.product_id = products.id JOIN products ON cart_items.product_id = products.id
WHERE cart_items.id = ? AND cart_items.session_id = ?`, WHERE cart_items.id = ? AND cart_items.user_id = ?`, // เปลี่ยนจาก session_id เป็น user_id
[cartItemId, req.session.id] [cartItemId, req.session.user.id]
); );
if (!cartItem) { if (!cartItem) {
...@@ -101,11 +101,11 @@ router.post('/update', async (req, res) => { ...@@ -101,11 +101,11 @@ router.post('/update', async (req, res) => {
} }
await pool.query( await pool.query(
'UPDATE cart_items SET quantity = ? WHERE id = ? AND session_id = ?', 'UPDATE cart_items SET quantity = ? WHERE id = ? AND user_id = ?',
[parseInt(quantity), cartItemId, req.session.id] [parseInt(quantity), cartItemId, req.session.user.id]
); );
const total = await calculateTotal(req.session.id); const total = await calculateTotal(req.session.user.id);
res.json({ total }); res.json({ total });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment