summaryrefslogtreecommitdiff
path: root/src/lib/product/components/Product/ProductDesktop.jsx
diff options
context:
space:
mode:
authorHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-10-16 11:28:34 +0700
committerHATEC\SPVDEV001 <tri.susilo@altama.co.id>2023-10-16 11:28:34 +0700
commit954be13467b02889414db600fee8e8b7b76cc2aa (patch)
tree4331a21338b2ac33b6f7a2911e61365b8950c33c /src/lib/product/components/Product/ProductDesktop.jsx
parentca445ab4e089b98fb67b004a6cb4a8968f471ae4 (diff)
parent6aa5fa70cf5ccd2825e5657ec1a90e370dea3bcf (diff)
Merge branch 'CR/UI' of https://bitbucket.org/altafixco/next-indoteknik into CR/UI
Diffstat (limited to 'src/lib/product/components/Product/ProductDesktop.jsx')
-rw-r--r--src/lib/product/components/Product/ProductDesktop.jsx44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 855c9f75..701750b2 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -90,38 +90,38 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
}
const updateCart = (variantId, quantity, source) => {
- let dataUpdate
+ let dataUpdate = {
+ productId: variantId,
+ quantity,
+ selected: true,
+ source: source === 'buy' ? 'buy' : null
+ }
+
if (product.variants.length > 1) {
let variantIndex = product.variants.findIndex((varian) => varian.id == variantId)
- dataUpdate = {
- productId: variantId,
- quantity,
- programLineId: product.variants[variantIndex].programActive,
- selected: true,
- source: source === 'buy' ? 'buy' : null
- }
+ dataUpdate['programLineId'] = product.variants[variantIndex].programActive
} else {
- dataUpdate = {
- productId: variantId,
- quantity,
- programLineId: promotionActiveId,
- selected: true,
- source: source === 'buy' ? 'buy' : null
- }
+ dataUpdate['programLineId'] = promotionActiveId
}
+
updateItemCart(dataUpdate)
}
- const handleAddToCart = (variantId) => {
- if (!auth) {
- router.push(`/login?next=/shop/product/${slug}`)
- return
- }
+ const redirectToLogin = (action, variantId, quantity) => {
+ const nextURL = `/shop/product/${slug}?action=${action}&variantId=${variantId}&qty=${quantity}`
+ router.push(`/login?next=${encodeURIComponent(nextURL)}`)
+ return true
+ }
+ const handleAddToCart = (variantId) => {
const quantity = variantQuantityRefs.current[variantId].value
if (!validQuantity(quantity)) return
+ if (!auth) {
+ return redirectToLogin('add_to_cart', variantId, quantity)
+ }
+
let source = 'cart'
updateCart(variantId, quantity, source)
setRefreshCart(true)
@@ -141,6 +141,10 @@ const ProductDesktop = ({ products, wishlist, toggleWishlist }) => {
const quantity = variantQuantityRefs.current[variant].value
if (!validQuantity(quantity)) return
+ if (!auth) {
+ return redirectToLogin('buy', variant, quantity)
+ }
+
let source = 'buy'
updateCart(variant, quantity, source)
router.push(`/shop/checkout?source=buy`)