fix bug cart

This commit is contained in:
hamid zarghami
2025-10-27 13:41:00 +03:30
parent abc74eb970
commit fcbbf4c67a
4 changed files with 34 additions and 10 deletions
+2
View File
@@ -9,6 +9,7 @@ import MobileBottomMenu from "@/components/MobileBottomMenu";
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { viewport } from './viewport'
import { SHOP_CONFIG } from "@/config/const";
import ManageData from "@/components/ManageData";
export const metadata: Metadata = {
title: `${SHOP_CONFIG.fullName} | ${SHOP_CONFIG.englishName}`,
@@ -33,6 +34,7 @@ export default function RootLayout({
<ToastContainer />
<MobileBottomMenu />
<ReactQueryDevtools initialIsOpen={false} />
<ManageData />
</QueryProvider>
</body>
</html>
@@ -41,7 +41,13 @@ const OnlineCart: React.FC<OnlineCartProps> = ({ variantId }) => {
useEffect(() => {
// Check API cart for logged in users
console.log('cart', cart);
console.log('variantId', variantId);
const item = cart?.results?.cart?.items?.find(item => item.variant?._id === variantId)
console.log('item', item);
if (item) {
setIsInCart(true)
setQuantity(item.quantity)
+7 -10
View File
@@ -1,13 +1,11 @@
'use client'
import { Button } from '@/components/ui/button'
import { Separator } from '@/components/ui/separator'
import { BoxTick, I3DRotate, Messages1 } from 'iconsax-react'
import { BoxTick, I3DRotate } from 'iconsax-react'
import React from 'react'
import { Product } from '@/types/product.types'
import Image from 'next/image'
import Cart from './Cart'
import { PRIMARY_COLOR } from '@/config/const'
import { useRouter } from 'next/navigation'
import { useProductStore } from '../store/Store'
interface ShopInformationProps {
@@ -15,7 +13,6 @@ interface ShopInformationProps {
}
const ShopInformation = ({ product }: ShopInformationProps) => {
const router = useRouter()
const { variantId } = useProductStore()
// پیدا کردن variant انتخابی یا استفاده از default_variant
@@ -35,10 +32,10 @@ const ShopInformation = ({ product }: ShopInformationProps) => {
const discountPercent = price.discount_percent
const hasDiscount = discountPercent > 0
const handleChatWithSeller = () => {
// Navigate to chat page with product and shop context
router.push(`/profile/chat?productId=${product._id}&shopId=${shop.owner}`)
}
// const handleChatWithSeller = () => {
// // Navigate to chat page with product and shop context
// router.push(`/profile/chat?productId=${product._id}&shopId=${shop.owner}`)
// }
return (
<div className='w-full xl:w-[325px] bg-[#FAFAFA] rounded-[10px] p-4 sm:p-6 lg:p-7 border border-border h-fit xl:sticky xl:top-[170px] xl:self-start'>
@@ -111,13 +108,13 @@ const ShopInformation = ({ product }: ShopInformationProps) => {
</div>
<Cart />
<Button
{/* <Button
onClick={handleChatWithSeller}
className='w-full mt-3 bg-[#323232] hover:bg-[#424242] flex items-center justify-center gap-2'
>
<Messages1 size={18} />
گفتگو با فروشنده
</Button>
</Button> */}
</div>
)
}
+19
View File
@@ -0,0 +1,19 @@
'use client'
import { useProductStore } from "@/app/product/store/Store";
import { usePathname } from "next/navigation";
import { useEffect } from "react";
const ManageData = () => {
const { setVariantId } = useProductStore()
const pathname = usePathname()
useEffect(() => {
setVariantId('')
}, [pathname]);
return null
}
export default ManageData