From 019068a387c29ec61b53031b68cf81000063186e Mon Sep 17 00:00:00 2001
From: "HATEC\\SPVDEV001" <tri.susilo@altama.co.id>
Date: Wed, 26 Jul 2023 14:05:53 +0700
Subject: add condition source

---
 .../product/components/Product/ProductDesktop.jsx  | 23 +++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

(limited to 'src/lib/product/components/Product/ProductDesktop.jsx')

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`)
   }
 
-- 
cgit v1.2.3

