This commit is contained in:
2025-11-18 16:18:43 +07:00
parent f150a84cf0
commit 08b352f686
10 changed files with 2140 additions and 27 deletions

View File

@@ -2,12 +2,15 @@ import api from './api';
export interface CartItem {
cartItemId: number;
productId: number;
productName: string;
productImage: string;
quantity: number;
price: number;
subtotal: number;
product: {
productId: number;
productName: string;
price: number;
imageUrl: string;
};
}
export interface CartResponse {
@@ -43,12 +46,20 @@ const cartService = {
// Lấy danh sách sản phẩm trong giỏ hàng
getCart: async (userId: number): Promise<CartResponse> => {
console.log('=== GET CART REQUEST ===', { userId });
const response = await api.get<CartResponse>(
`/cart/${userId}`,
{ requireAuth: true }
);
console.log('=== GET CART RESPONSE ===', response);
// MAP lại items để UI dùng dễ hơn
response.items = response.items.map(item => ({
...item,
productName: item.product.productName,
productImage: item.product.imageUrl,
price: Number(item.product.price),
subtotal: Number(item.subtotal),
}));
return response;
},