diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2023-07-26 07:03:56 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2023-07-26 07:03:56 +0000 |
| commit | cea5468a29e70aec335e2e80c7fa03e35a3c73bf (patch) | |
| tree | b96995779374d24d3bfb498ec12f574d3aa37f3a | |
| parent | 3f9acbd9ee447fb5cf45cbd07821ad60c9d2f331 (diff) | |
| parent | 019068a387c29ec61b53031b68cf81000063186e (diff) | |
Merged in Hotfix/action_click_button_beli (pull request #28)
add condition source
| -rw-r--r-- | src/core/utils/cart.js | 6 | ||||
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 23 |
2 files changed, 18 insertions, 11 deletions
diff --git a/src/core/utils/cart.js b/src/core/utils/cart.js index dcb104f9..598f4a74 100644 --- a/src/core/utils/cart.js +++ b/src/core/utils/cart.js @@ -35,8 +35,10 @@ const addCart = async (product_id, qty, selected, programLineId = null, source) 'product_id' : product_id, 'qty' : qty, 'selected' : selected, - 'program_line_id' : programLineId, - 'source' : source + 'program_line_id' : programLineId + } + if(source){ + data.source = source } const id = getAuth()?.id 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`) } |
