diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-03-28 09:22:13 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-03-28 09:22:13 +0700 |
| commit | 8ca9069251873e87338f1c7f581b418bebb11e9a (patch) | |
| tree | 12e651361cb667c768961932a99d0a253ffee4e7 /src/lib/cart/components | |
| parent | fd2a6bcf2f17a6dbcbfb3ca04ebf2c4d66d43437 (diff) | |
| parent | a040418bdddd5fcaf8a8d67e0a66ea92fd16ee24 (diff) | |
Merge branch 'master' of https://bitbucket.org/altafixco/next-indoteknik
Diffstat (limited to 'src/lib/cart/components')
| -rw-r--r-- | src/lib/cart/components/Cart.jsx | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/lib/cart/components/Cart.jsx b/src/lib/cart/components/Cart.jsx index 8cd6df96..7ebee14b 100644 --- a/src/lib/cart/components/Cart.jsx +++ b/src/lib/cart/components/Cart.jsx @@ -14,6 +14,7 @@ import Spinner from '@/core/components/elements/Spinner/Spinner' import Alert from '@/core/components/elements/Alert/Alert' import MobileView from '@/core/components/views/MobileView' import DesktopView from '@/core/components/views/DesktopView' +import variantPriceApi from '@/lib/variant/api/variantPriceApi' const Cart = () => { const router = useRouter() @@ -28,16 +29,24 @@ const Cart = () => { useEffect(() => { if (cart.data && !products) { - const productsWithQuantity = cart.data.map((product) => { + const productsWithQuantity = cart.data.map(async (product) => { const productInCart = getItemCart({ productId: product.id }) if (!productInCart) return + const productPrice = await variantPriceApi({ id: product.id }) return { ...product, + price: { + price: productPrice.priceExclude, + discountPercentage: productPrice.discount, + priceDiscount: productPrice.priceExcludeAfterDiscount + }, quantity: productInCart.quantity, selected: productInCart.selected } }) - setProducts(productsWithQuantity) + Promise.all(productsWithQuantity).then((resolvedProducts) => { + setProducts(resolvedProducts) + }) } }, [cart, products]) @@ -84,11 +93,11 @@ const Cart = () => { quantity -= value break case 'BLUR': - if (value != '') return + if (value != '' && value > 0) return quantity = 1 break default: - quantity = value + quantity = value != '' && value < 1 ? 1 : value break } productsToUpdate[productIndex].quantity = quantity |
