summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-02-20 11:25:55 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-02-20 11:25:55 +0700
commita7160110ab082109e96696c3bc2321f28610958c (patch)
tree52f88b955e57f866fe191c2dad765e11b4cb9016 /src
parentbfa3cf8546e1a45941e8388b251b91975f95bfd3 (diff)
<iman> add google tag button add to cart
Diffstat (limited to 'src')
-rw-r--r--src/lib/product/components/Product/ProductDesktopVariant.jsx52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx
index 5dfd452b..de88e5bb 100644
--- a/src/lib/product/components/Product/ProductDesktopVariant.jsx
+++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx
@@ -26,7 +26,7 @@ import ProductCard from '../ProductCard';
import ProductSimilar from '../ProductSimilar';
import ProductPromoSection from '~/modules/product-promo/components/Section';
import SimilarBottom from '~/modules/product-detail/components/SimilarBottom';
-
+import { gtagAddToCart } from '@/core/utils/googleTag';
const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST;
const ProductDesktopVariant = ({
@@ -41,14 +41,38 @@ const ProductDesktopVariant = ({
const { srsltid } = router.query;
const [askAdminUrl, setAskAdminUrl, isApproval] = useState();
const [lowestPrice, setLowestPrice] = useState(null);
-
+ const [qtyPickUp, setQtyPickUp] = useState(0);
const [addCartAlert, setAddCartAlert] = useState(false);
const [isLoadingSLA, setIsLoadingSLA] = useState(true);
-
+ const [selectedVariant, setSelectedVariant] = useState(product.id);
const { setRefreshCart } = useProductCartContext();
const [quantityInput, setQuantityInput] = useState(1);
+ const [activeVariant, setActiveVariant] = useState({
+ id: null,
+ code: product.code,
+ name: product.name,
+ price: lowestPrice,
+ stock: product.stockTotal,
+ weight: product.weight,
+ isFlashSale: product.isFlashSale,
+ });
+
+ useEffect(() => {
+ if (selectedVariant) {
+ setActiveVariant({
+ id: product.id,
+ code: product.code,
+ name: product.name,
+ price: product.price,
+ stock: product.stockTotal,
+ weight: product.weight,
+ isFlashSale: product.isFlashSale,
+ });
+ }
+ }, [selectedVariant, product]);
+
const createdAskUrl = whatsappUrl({
template: 'product',
payload: {
@@ -95,6 +119,7 @@ const ProductDesktopVariant = ({
}
const quantity = quantityInput;
if (!validQuantity(quantity)) return;
+ gtagAddToCart(activeVariant, quantity);
updateItemCart({
productId: product.id,
quantity,
@@ -232,6 +257,17 @@ const ProductDesktopVariant = ({
fetchData();
}, [product]);
+ useEffect(() => {
+ const fetchData = async () => {
+ const qty_available = await odooApi(
+ 'GET',
+ `/api/v1/product_variant/${product.id}/qty_available`
+ );
+ setQtyPickUp(qty_available?.qty);
+ };
+ fetchData();
+ }, [product]);
+
return (
<DesktopView>
<div className='container mx-auto pt-10'>
@@ -451,7 +487,7 @@ const ProductDesktopVariant = ({
</Skeleton>
</div>
<div>
- {product?.sla?.qty > 0 && (
+ {qtyPickUp > 0 && (
<Link href='/panduan-pick-up-service' className='group'>
<Image
src='/images/PICKUP-NOW.png'
@@ -462,6 +498,14 @@ const ProductDesktopVariant = ({
)}
</div>
</div>
+ {qtyPickUp > 0 && (
+ <>
+ <div className='text-[12px] mt-1 text-red-500 italic'>
+ * {qtyPickUp} barang bisa di pickup
+ </div>
+ <div className='h-4' />
+ </>
+ )}
<div className='flex gap-x-3'>
<Button
onClick={() => handleAddToCart(product.id)}