Gitlab@Informatics

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

update-cart

parent b59223f2
No related branches found
No related tags found
No related merge requests found
......@@ -17,22 +17,17 @@ async function calculateTotal(sessionId) {
// แสดงตะกร้าสินค้า
router.get('/', async (req, res) => {
try {
if (!req.session.user) {
return res.status(401).send('Unauthorized');
}
const [cartItems] = await pool.query(
`SELECT cart_items.*, products.name, products.price, products.stock, products.description
`SELECT cart_items.*, products.name, products.price, products.stock
FROM cart_items
JOIN products ON cart_items.product_id = products.id
WHERE cart_items.user_id = ?`,
[req.session.user.id]
WHERE session_id = ?`,
[req.session.id]
);
const total = await calculateTotal(req.session.user.id);
const total = await calculateTotal(req.session.id);
res.render('cart', { cartItems, total });
} catch (error) {
console.error("Error fetching cart:", error);
console.error(error);
res.status(500).send('Error fetching cart');
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment