From b237658bb93f7e563362b2540c763ed41e20bc4b Mon Sep 17 00:00:00 2001 From: PhuocNTB Date: Thu, 9 Oct 2025 09:45:37 +0700 Subject: [PATCH] zzz --- db.json | 2 +- src/apis/core/cart.api.ts | 3 +-- src/pages/home/cart/Cart.tsx | 19 ++++++++++++++++++- src/pages/home/product/ProductDetail.tsx | 20 ++++++++++++-------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/db.json b/db.json index ccc7a3b..f3d29c6 100644 --- a/db.json +++ b/db.json @@ -79,7 +79,7 @@ "id": "c06c", "productId": "d317", "userId": "1", - "quantity": 1 + "quantity": 2 } ] } \ No newline at end of file diff --git a/src/apis/core/cart.api.ts b/src/apis/core/cart.api.ts index 102731f..21b79bb 100644 --- a/src/apis/core/cart.api.ts +++ b/src/apis/core/cart.api.ts @@ -12,7 +12,6 @@ export const CartApi = { }, addToCart: async (data: AddToCartDTO) => { let resultExisted = await axios.get(`${import.meta.env.VITE_SV_HOST}/carts?productId=${data.productId}`) - console.log("resultExisted", resultExisted.data) if (!resultExisted.data[0]) { /* thêm mới */ await axios.post(`${import.meta.env.VITE_SV_HOST}/carts`, { @@ -28,6 +27,6 @@ export const CartApi = { quantity: resultExisted.data[0].quantity + 1 }) - console.log("resultUpdate", resultUpdate.data) + return true } } \ No newline at end of file diff --git a/src/pages/home/cart/Cart.tsx b/src/pages/home/cart/Cart.tsx index dc37455..950a7a8 100644 --- a/src/pages/home/cart/Cart.tsx +++ b/src/pages/home/cart/Cart.tsx @@ -2,11 +2,28 @@ import React from 'react' import { useSelector } from 'react-redux' import type { StoreType } from '../../../stores' import type { CartItem } from '../../../types/cart.type' +import { Apis } from '../../../apis' +import type { Product } from '../../../types/product.type' export default function Cart() { const userStore = useSelector((store: StoreType) => store.user) - + // + //đây là api lấy product id let data = Apis.product.findProductById(productId) + // data có interface là Product + // cho bạn interface product luôn + /* + export interface Product { + id: string; + categoryId: string; + price: number; + iconUrl: string; + isActive: boolean; + name: string; + des: string; +} + + */ return (
Cart Page diff --git a/src/pages/home/product/ProductDetail.tsx b/src/pages/home/product/ProductDetail.tsx index e575754..9b5c34b 100644 --- a/src/pages/home/product/ProductDetail.tsx +++ b/src/pages/home/product/ProductDetail.tsx @@ -29,11 +29,16 @@ export default function ProductDetail() { return (
-
{/* Hình ảnh sản phẩm */} @@ -52,11 +57,10 @@ export default function ProductDetail() { {product.price.toLocaleString()} ₫

{product.isActive ? 'Đang bán' : 'Ngừng kinh doanh'}