diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-26 13:21:07 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-26 13:21:07 +0700 |
| commit | a3d4259a70ca24dadf1e86d392efc05818d9327e (patch) | |
| tree | 3a1c93bef559748a50f8ed68b66e390c3656cc13 /src/lib/product | |
| parent | a72a7503dd5f04c9f3db5a3803dce0610fcff7ea (diff) | |
fixing jika beli langsung
Diffstat (limited to 'src/lib/product')
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 2a523503..9be65bfb 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -63,7 +63,6 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { variantQuantityRefs.current[variantId] = element } - const validQuantity = (quantity) => { let isValid = true if (!quantity || quantity < 1 || isNaN(parseInt(quantity))) { @@ -73,38 +72,46 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { return isValid } - const handleAddToCart = (variantId) => { - if (!auth) { - router.push(`/login?next=/shop/product/${slug}`) - return - } - const quantity = variantQuantityRefs.current[variantId].value - - if (!validQuantity(quantity)) return - if(product.variants.length > 1){ + const updateCart = (variantId, quantity) => { + if (product.variants.length > 1) { let variantIndex = product.variants.findIndex((varian) => varian.id == variantId) updateItemCart({ productId: variantId, quantity, programLineId: product.variants[variantIndex].programActive, - selected: true + selected: true, + source: 'buy' }) - }else{ + } else { updateItemCart({ productId: variantId, quantity, programLineId: promotionActiveId, - selected: true + selected: true, + source: 'buy' }) } - + } + + const handleAddToCart = (variantId) => { + if (!auth) { + router.push(`/login?next=/shop/product/${slug}`) + return + } + const quantity = variantQuantityRefs.current[variantId].value + + if (!validQuantity(quantity)) return + + updateCart(variantId, quantity) setAddCartAlert(true) } const handleBuy = (variant) => { const quantity = variantQuantityRefs.current[variant].value if (!validQuantity(quantity)) return - router.push(`/shop/checkout?productId=${variant}&quantity=${quantity}`) + + updateCart(variant, quantity) + router.push(`/shop/checkout?source=buy`) } const variantSectionRef = useRef(null) @@ -351,11 +358,11 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { <a href={whatsappUrl('product', { name: product.name, - manufacture: product.manufacture?.name , + manufacture: product.manufacture?.name, url: createSlug('/shop/product/', product.name, product.id, true) })} className='text-danger-500 underline' - rel="noopener noreferrer" + rel='noopener noreferrer' target='_blank' > klik disini @@ -460,8 +467,8 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { url: createSlug('/shop/product/', product.name, product.id, true) })} className='text-danger-500 font-medium' - target="_blank" - rel="noreferrer noopener" + target='_blank' + rel='noreferrer noopener' > Tanya Admin </a> @@ -526,11 +533,11 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { <a href={whatsappUrl('product', { name: variant.name, - manufacture: product.manufacture?.name , + manufacture: product.manufacture?.name, url: createSlug('/shop/product/', product.name, product.id, true) })} className='text-red_r-11' - rel="noopener noreferrer" + rel='noopener noreferrer' target='_blank' > Call for price |
