summaryrefslogtreecommitdiff
path: root/src/lib/checkout/components/Checkout.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/checkout/components/Checkout.jsx')
-rw-r--r--src/lib/checkout/components/Checkout.jsx27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index b4fd33ff..ef0b1d54 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -64,19 +64,26 @@ const Checkout = () => {
useEffect(() => {
const loadProducts = async () => {
- const cart = getCart()
- const variantIds = _.filter(cart, (o) => o.selected == true)
- .map((o) => o.productId)
- .join(',')
+ let variantIds = ''
+ let { query } = router
+ if (query?.productId) {
+ variantIds = query.productId
+ } else {
+ const cart = getCart()
+ variantIds = _.filter(cart, (o) => o.selected == true)
+ .map((o) => o.productId)
+ .join(',')
+ }
+
const dataProducts = await CartApi({ variantIds })
const dataProductsQuantity = _.map(dataProducts, (o) => ({
...o,
- quantity: getItemCart({ productId: o.id }).quantity
+ quantity: query.quantity ? query.quantity : getItemCart({ productId: o.id }).quantity
}))
setProducts(dataProductsQuantity)
}
loadProducts()
- }, [])
+ }, [router])
useEffect(() => {
if (products) {
@@ -128,7 +135,7 @@ const Checkout = () => {
toast.error('Gagal melakukan transaksi, terjadi kesalahan internal')
return
}
-
+
for (const product of products) deleteItemCart({ productId: product.id })
if (paymentMethod == 'midtrans') {
const payment = await axios.post(
@@ -296,12 +303,6 @@ const Checkout = () => {
{isLoading ? 'Loading...' : 'Bayar'}
</button>
</div>
-
- <Script
- async
- src='https://app.sandbox.midtrans.com/snap/snap.js'
- data-client-key={process.env.NEXT_PUBLIC_MIDTRANS_CLIENT_KEY}
- />
</>
)
}