diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-26 14:05:53 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-07-26 14:05:53 +0700 |
| commit | 019068a387c29ec61b53031b68cf81000063186e (patch) | |
| tree | 1b6c5dd94b373212553de5099d88a6a00d423869 /src/lib | |
| parent | d6761519478ba351099b5d60083f318ad0812305 (diff) | |
add condition source
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 9be65bfb..cf4d9b0d 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -72,25 +72,28 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { return isValid } - const updateCart = (variantId, quantity) => { + const updateCart = (variantId, quantity, source) => { + let dataUpdate if (product.variants.length > 1) { let variantIndex = product.variants.findIndex((varian) => varian.id == variantId) - updateItemCart({ + dataUpdate = { productId: variantId, quantity, programLineId: product.variants[variantIndex].programActive, selected: true, - source: 'buy' - }) + source : source === 'buy' ? 'buy' : null + } + } else { - updateItemCart({ + dataUpdate = { productId: variantId, quantity, programLineId: promotionActiveId, selected: true, - source: 'buy' - }) + source : source === 'buy' ? 'buy' : null + } } + updateItemCart(dataUpdate) } const handleAddToCart = (variantId) => { @@ -102,7 +105,8 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { if (!validQuantity(quantity)) return - updateCart(variantId, quantity) + let source = 'cart' + updateCart(variantId, quantity, source) setAddCartAlert(true) } @@ -110,7 +114,8 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => { const quantity = variantQuantityRefs.current[variant].value if (!validQuantity(quantity)) return - updateCart(variant, quantity) + let source = 'buy' + updateCart(variant, quantity, source) router.push(`/shop/checkout?source=buy`) } |
