diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2025-05-14 09:27:26 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2025-05-14 09:27:26 +0700 |
| commit | 29ecab270822500ead372d8d3e05c9281a514715 (patch) | |
| tree | a32735f4b7fab774de6a2bbee9380f363c51bec2 /src-migrate/modules/product-detail/components/AddToCart.tsx | |
| parent | dd66804b05166ad6bb71bf54fe3374d9897fee86 (diff) | |
| parent | 746a11b810ae9e8a974a76d0548297cd0faff9b5 (diff) | |
Merge branch 'new-release' into CR/form-merchant
Diffstat (limited to 'src-migrate/modules/product-detail/components/AddToCart.tsx')
| -rw-r--r-- | src-migrate/modules/product-detail/components/AddToCart.tsx | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src-migrate/modules/product-detail/components/AddToCart.tsx b/src-migrate/modules/product-detail/components/AddToCart.tsx index 280e4a7a..95bc1d88 100644 --- a/src-migrate/modules/product-detail/components/AddToCart.tsx +++ b/src-migrate/modules/product-detail/components/AddToCart.tsx @@ -15,7 +15,8 @@ import { useProductCartContext } from '@/contexts/ProductCartContext'; import { createSlug } from '~/libs/slug'; import formatCurrency from '~/libs/formatCurrency'; import { useProductDetail } from '../stores/useProductDetail'; - +import { gtagAddToCart } from '@/core/utils/googleTag'; +import axios from 'axios'; type Props = { variantId: number | null; quantity?: number; @@ -50,6 +51,38 @@ const AddToCart = ({ isLoading, setIsloading, } = useProductCartContext(); + const [activeVariant, setActiveVariant] = useState({ + id: 0, + code: '', + name: '', + price: '', + stock: '', + weight: '', + isFlashSale: false, + }); + + useEffect(() => { + const fetchData = async () => { + if (variantId) { + let response = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant-detail?id=${variantId}` + ); + let productVariant = response.data; + if (productVariant) { + setActiveVariant({ + id: productVariant[0].id, + code: productVariant[0].code, + name: productVariant[0].name, + price: productVariant[0].price.price, + stock: productVariant[0].stockTotal, + weight: productVariant[0].weight, + isFlashSale: productVariant[0].isFlashsale, + }); + } + } + }; + fetchData(); + }, [variantId]); const productSimilarQuery = [ product?.name, @@ -101,6 +134,8 @@ const AddToCart = ({ setRefreshCart(true); setAddCartAlert(true); + gtagAddToCart(activeVariant, quantity); + toast({ title: 'Tambah ke keranjang', description: 'Berhasil menambahkan barang ke keranjang belanja', |
