From 0ee7434188364dc230bbd034dc165a0f4850e3db Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Sat, 3 Jun 2023 11:16:32 +0700 Subject: Add gtag event on product detail --- src/lib/product/components/Product/Product.jsx | 6 ++++++ src/lib/product/components/Product/ProductDesktop.jsx | 14 ++++++++------ src/lib/product/components/Product/ProductMobile.jsx | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/Product.jsx b/src/lib/product/components/Product/Product.jsx index 9521cbe4..351c07c1 100644 --- a/src/lib/product/components/Product/Product.jsx +++ b/src/lib/product/components/Product/Product.jsx @@ -5,6 +5,8 @@ import ProductDesktop from './ProductDesktop' import useAuth from '@/core/hooks/useAuth' import ProductMobile from './ProductMobile' import { useRouter } from 'next/router' +import { useEffect } from 'react' +import { gtagViewItem } from '@/core/utils/googleTag' const Product = ({ product }) => { const auth = useAuth() @@ -26,6 +28,10 @@ const Product = ({ product }) => { wishlist.refetch() } + useEffect(() => { + gtagViewItem(product.variants) + }, [product]) + return ( <> diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 75b37b9d..4a584761 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -14,6 +14,7 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup' import ProductCard from '../ProductCard' import productSimilarApi from '../../api/productSimilarApi' import whatsappUrl from '@/core/utils/whatsappUrl' +import { gtagAddToCart } from '@/core/utils/googleTag' const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { const router = useRouter() @@ -52,11 +53,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { return isValid } - const handleAddToCart = (variantId) => { - const quantity = variantQuantityRefs.current[variantId].value + const handleAddToCart = (variant) => { + const quantity = variantQuantityRefs.current[variant.id].value if (!validQuantity(quantity)) return + gtagAddToCart(variant, quantity) updateItemCart({ - productId: variantId, + productId: variant.id, quantity, selected: true }) @@ -247,14 +249,14 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { /> + + + +
+ +
+ +
+
+ Produk Serupa +
+
+ {productSimilarInBrand && + productSimilarInBrand?.map((product) => ( +
+ +
+ ))} +
+
+ + + +
+
Kamu Mungkin Juga Suka
+ + + +
+ + setAddCartAlert(false)} + > +
+
+ {product.name} +
+
{product.name}
+
+ + Lihat Keranjang + +
+
+ +
+
Kamu Mungkin Juga Suka
+ + + +
+
+ + + ) +} + +const informationTabOptions = [ + { value: 'description', label: 'Deskripsi' }, + { value: 'information', label: 'Info Penting' } +] + +const TabButton = ({ children, active, ...props }) => { + const activeClassName = active + ? 'text-danger-500 underline underline-offset-4' + : 'text-gray_r-12/80' + return ( + + ) +} + +const TabContent = ({ children, active, className = '', ...props }) => ( +
+ {children} +
+) + +export default ProductDesktopVariant diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx new file mode 100644 index 00000000..29d7700d --- /dev/null +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -0,0 +1,315 @@ +import Divider from '@/core/components/elements/Divider/Divider' +import Image from '@/core/components/elements/Image/Image' +import Link from '@/core/components/elements/Link/Link' +import currencyFormat from '@/core/utils/currencyFormat' +import { useEffect, useState } from 'react' +import Select from 'react-select' +import ProductSimilar from '../ProductSimilar' +import LazyLoad from 'react-lazy-load' +import { updateItemCart } from '@/core/utils/cart' +import { HeartIcon } from '@heroicons/react/24/outline' +import { useRouter } from 'next/router' +import MobileView from '@/core/components/views/MobileView' +import { toast } from 'react-hot-toast' +import { createSlug } from '@/core/utils/slug' +import BottomPopup from '@/core/components/elements/Popup/BottomPopup' +import whatsappUrl from '@/core/utils/whatsappUrl' +import { gtagAddToCart } from '@/core/utils/googleTag' + +const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { + const router = useRouter() + + const [quantity, setQuantity] = useState('1') + const [selectedVariant, setSelectedVariant] = useState(product.id) + const [informationTab, setInformationTab] = useState(informationTabOptions[0].value) + const [addCartAlert, setAddCartAlert] = useState(false) + + const getLowestPrice = () => { + const lowest = product.price + return lowest + } + + const [activeVariant, setActiveVariant] = useState({ + id: null, + code: product.code, + name: product.name, + price: getLowestPrice(), + stock: product.stockTotal, + weight: product.weight + }) + + useEffect(() => { + if (selectedVariant) { + setActiveVariant({ + id: product.id, + code: product.code, + name: product.name, + price: product.price, + stock: product.stock, + weight: product.weight + }) + } + }, [selectedVariant, product]) + + const validAction = () => { + let isValid = true + if (!selectedVariant) { + toast.error('Pilih varian terlebih dahulu') + isValid = false + } + if (!quantity || quantity < 1 || isNaN(parseInt(quantity))) { + toast.error('Jumlah barang minimal 1') + isValid = false + } + return isValid + } + + const handleClickCart = () => { + if (!validAction()) return + gtagAddToCart(activeVariant, quantity) + updateItemCart({ + productId: activeVariant.id, + quantity, + selected: true + }) + setAddCartAlert(true) + } + + const handleClickBuy = () => { + if (!validAction()) return + router.push(`/shop/checkout?productId=${activeVariant.id}&quantity=${quantity}`) + } + + const productSimilarQuery = [ + product?.name, + `fq=-product_id_i:${product.id}`, + `fq=-manufacture_id_i:${product.manufacture?.id || 0}` + ].join('&') + + return ( + + {product.name} + +
+
+ {product.manufacture?.name ? ( + + {product.manufacture?.name} + + ) : ( +
-
+ )} + +
+

{activeVariant?.name}

+ + {activeVariant?.price?.discountPercentage > 0 && ( +
+
+ {currencyFormat(activeVariant?.price?.price * 1.11)} +
+
{activeVariant?.price?.discountPercentage}%
+
+ )} +

+ {currencyFormat(activeVariant?.price?.priceDiscount)} +

+

+ {activeVariant?.price?.priceDiscount > 0 ? ( + currencyFormat(activeVariant?.price?.priceDiscount * 1.11) + ) : ( + + Hubungi kami untuk dapatkan harga terbaik,  + + klik disini + + + )} + + {activeVariant?.price?.priceDiscount > 0 && ( + *include PPN + )} +

+
+ + + +
+
Jumlah
+
+
+ setQuantity(e.target.value)} + /> +
+ + +
+
+ + + +
+

Informasi Produk

+
+ {informationTabOptions.map((option) => ( + setInformationTab(option.value)} + > + {option.label} + + ))} +
+ + + + SKU-{product?.id} + + + {activeVariant?.code || '-'} + + + {activeVariant?.stock > 0 && ( + +
Ready Stock
+
{activeVariant?.stock > 5 ? '> 5' : '< 5'}
+
+ )} + {activeVariant?.stock == 0 && ( + + Tanya Stok + + )} +
+ + {activeVariant?.weight > 0 && {activeVariant?.weight} KG} + {activeVariant?.weight == 0 && ( + + Tanya Berat + + )} + +
+ + +
+ + + +
+

Kamu Mungkin Juga Suka

+ + + +
+ + setAddCartAlert(false)} + > +
+
+ {product.name} +
+
{product.name}
+
+ + Lihat Keranjang + +
+
+
+
Kamu Mungkin Juga Suka
+ + + +
+
+
+ ) +} + +const informationTabOptions = [ + { value: 'specification', label: 'Spesifikasi' } + // { value: 'description', label: 'Deskripsi' }, + // { value: 'information', label: 'Info Penting' } +] + +const TabButton = ({ children, active, ...props }) => { + const activeClassName = active ? 'text-danger-500 underline underline-offset-4' : 'text-gray_r-11' + return ( + + ) +} + +const TabContent = ({ children, active, className, ...props }) => ( +
+ {children} +
+) + +const SpecificationContent = ({ children, label }) => ( +
+ {label} + {children} +
+) + +export default ProductMobileVariant -- cgit v1.2.3 From 9bbb8d45420eca5a5987a43b55c2a4bec01f19fe Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Thu, 22 Jun 2023 13:39:23 +0700 Subject: xml google merchnt --- src/lib/product/api/variantSearchApi.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/lib/product/api/variantSearchApi.js (limited to 'src/lib/product') diff --git a/src/lib/product/api/variantSearchApi.js b/src/lib/product/api/variantSearchApi.js new file mode 100644 index 00000000..d7b05423 --- /dev/null +++ b/src/lib/product/api/variantSearchApi.js @@ -0,0 +1,11 @@ +import _ from 'lodash-contrib' +import axios from 'axios' + +const variantSearchApi = async ({ query, operation = 'AND' }) => { + const dataProductSearch = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/variant?${query}&operation=${operation}` + ) + return dataProductSearch.data +} + +export default variantSearchApi -- cgit v1.2.3 From 033b880d1a88e2fc0cd5bb8bce2ed24dae3e94ea Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Thu, 22 Jun 2023 16:57:41 +0700 Subject: change layout --- .../components/Product/ProductDesktopVariant.jsx | 56 ++++++++++++---------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx index a98985c9..557bcc0e 100644 --- a/src/lib/product/components/Product/ProductDesktopVariant.jsx +++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx @@ -195,42 +195,46 @@ const ProductDesktopVariant = ({ product, wishlist, toggleWishlist, isVariant }) */} -
+
+
+ Harga Sebelum PPN : +
+
+ + {currencyFormat(lowestPrice?.priceDiscount)} + +
+
+ Termasuk PPN : {lowestPrice?.discountPercentage > 0 && ( -
+
{lowestPrice?.discountPercentage}%
{currencyFormat(lowestPrice?.price * 1.11)}
+

+ {lowestPrice?.priceDiscount > 0 ? ( + currencyFormat(lowestPrice?.priceDiscount * 1.11) + ) : ( + + Hubungi kami untuk dapatkan harga terbaik,  + + klik disini + + + )} +

)} -

- {currencyFormat(lowestPrice?.priceDiscount)} -

-

- {lowestPrice?.priceDiscount > 0 ? ( - currencyFormat(lowestPrice?.priceDiscount * 1.11) - ) : ( - - Hubungi kami untuk dapatkan harga terbaik,  - - klik disini - - - )} - {lowestPrice?.priceDiscount > 0 && ( - *include PPN - )} -

Date: Fri, 23 Jun 2023 09:32:49 +0700 Subject: change request layout harga --- .../components/Product/ProductDesktopVariant.jsx | 75 +++++++++++----------- .../components/Product/ProductMobileVariant.jsx | 71 +++++++++++--------- 2 files changed, 76 insertions(+), 70 deletions(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx index 557bcc0e..e0573357 100644 --- a/src/lib/product/components/Product/ProductDesktopVariant.jsx +++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx @@ -196,46 +196,45 @@ const ProductDesktopVariant = ({ product, wishlist, toggleWishlist, isVariant })
*/}
-
-
- Harga Sebelum PPN : -
-
- - {currencyFormat(lowestPrice?.priceDiscount)} - -
-
- Termasuk PPN : - {lowestPrice?.discountPercentage > 0 && ( -
-
- {lowestPrice?.discountPercentage}% + {lowestPrice?.priceDiscount > 0 ? ( + <> +
+
+ Harga Sebelum PPN : +
+
+ + {currencyFormat(lowestPrice?.priceDiscount)} + +
-
- {currencyFormat(lowestPrice?.price * 1.11)} + Termasuk PPN : +
+
+ {lowestPrice?.discountPercentage}% +
+
+ {currencyFormat(lowestPrice?.price * 1.11)} +
+

+ {currencyFormat(lowestPrice?.priceDiscount * 1.11)} +

-

- {lowestPrice?.priceDiscount > 0 ? ( - currencyFormat(lowestPrice?.priceDiscount * 1.11) - ) : ( - - Hubungi kami untuk dapatkan harga terbaik,  - - klik disini - - - )} -

-
+ + ) : ( + + Hubungi kami untuk dapatkan harga terbaik,  + + klik disini + + )} -
-
-
Produk Serupa diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx index 29d7700d..26c3fea3 100644 --- a/src/lib/product/components/Product/ProductMobileVariant.jsx +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -115,39 +115,48 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {

{activeVariant?.name}

- {activeVariant?.price?.discountPercentage > 0 && ( -
-
- {currencyFormat(activeVariant?.price?.price * 1.11)} + {activeVariant?.price?.priceDiscount > 0 ? ( + <> +
+
Harga Sebelum PPN :
+
+ {' '} + {currencyFormat(activeVariant?.price?.priceDiscount)} +
-
{activeVariant?.price?.discountPercentage}%
-
+
+ Termasuk PPN : +
+ {activeVariant?.price?.discountPercentage > 0 && ( + <> +
+ {activeVariant?.price?.discountPercentage}% +
+
+ {currencyFormat(activeVariant?.price?.price * 1.11)} +
+ + )} +

+ {currencyFormat(activeVariant?.price?.priceDiscount * 1.11)} +

+
+
+ + ) : ( + + Hubungi kami untuk dapatkan harga terbaik,  + + klik disini + + )} -

- {currencyFormat(activeVariant?.price?.priceDiscount)} -

-

- {activeVariant?.price?.priceDiscount > 0 ? ( - currencyFormat(activeVariant?.price?.priceDiscount * 1.11) - ) : ( - - Hubungi kami untuk dapatkan harga terbaik,  - - klik disini - - - )} - - {activeVariant?.price?.priceDiscount > 0 && ( - *include PPN - )} -

-- cgit v1.2.3 From c4e0051472ce343212ea98768d59f367ba9ca727 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 4 Jul 2023 13:42:00 +0700 Subject: fixing label sebelum ppn --- src/lib/product/components/Product/ProductMobileVariant.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx index 26c3fea3..958b00cc 100644 --- a/src/lib/product/components/Product/ProductMobileVariant.jsx +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -118,7 +118,7 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { {activeVariant?.price?.priceDiscount > 0 ? ( <>
-
Harga Sebelum PPN :
+
Harga Sebelum PPN :
{' '} {currencyFormat(activeVariant?.price?.priceDiscount)} -- cgit v1.2.3 From 3f890e6d482cefba37014e021cb4c2b8d5de2a9d Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Wed, 12 Jul 2023 14:31:07 +0700 Subject: cr --- src/lib/product/components/Product/ProductDesktop.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 6a87d022..cafab721 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -66,9 +66,9 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { } const handleBuy = (variant) => { - const quantity = variantQuantityRefs.current[variant.id].value + const quantity = variantQuantityRefs.current[variant].value if (!validQuantity(quantity)) return - router.push(`/shop/checkout?productId=${variant.id}&quantity=${quantity}`) + router.push(`/shop/checkout?productId=${variant}&quantity=${quantity}`) } const variantSectionRef = useRef(null) -- cgit v1.2.3 From b886fcf2dbc9114bc2e2347e3d4bf5299ed43d3b Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 14 Jul 2023 09:26:08 +0700 Subject: toggle on off --- src/lib/product/components/Product/ProductDesktop.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/product') diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index cafab721..037b8c66 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -256,7 +256,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {