From 9159b649258703ea0539ea958cdf8b3c5987e474 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 15 Aug 2025 09:48:06 +0700
Subject: <hafid> fix alur repeat order

---
 src/lib/transaction/components/Transactions.jsx | 39 +++++++++++++------------
 1 file changed, 21 insertions(+), 18 deletions(-)

(limited to 'src/lib/transaction/components/Transactions.jsx')

diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx
index de93d742..2596b47f 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -345,8 +345,6 @@ const Transactions = ({ context = '' }) => {
   }, []);
 
   const handleBuyBack = async (products) => {
-    // if (status === 'success') return;
-
     try {
       // setStatus('loading');
 
@@ -358,32 +356,37 @@ const Transactions = ({ context = '' }) => {
             id: product.id,
             qty: product.quantity,
             selected: true,
-            source: 'buy', // Tetap gunakan 'buy' agar bisa masuk ke halaman pembelian
+            source: 'buy',
             qtyAppend: false,
+          }).catch(error => {
+            return { error, product };
           })
         )
       );
 
-      // ✅ Panggil setRefreshCart(true) setiap kali satu produk berhasil ditambahkan
+      const failedOperations = results.filter(result => result && result.error);
+      
+      if (failedOperations.length > 0) {
+        console.error('Some products failed to add to cart:', failedOperations);
+        toast.error(`${failedOperations.length} produk gagal ditambahkan ke keranjang`);
+        
+        // You might want to proceed with the successful ones or handle differently
+        if (failedOperations.length < products.length) {
+          toast.success(`${products.length - failedOperations.length} produk berhasil ditambahkan ke keranjang`);
+          setRefreshCart(true);
+          router.push('/shop/cart');
+        }
+        return;
+      }
 
+      // All operations succeeded
       setRefreshCart(true);
-
-      // setStatus('idle');
       toast.success('Semua produk berhasil ditambahkan ke keranjang belanja');
-      // Tampilkan notifikasi
-      // toast({
-      //   title: 'Tambah ke keranjang',
-      //   description: 'Semua produk berhasil ditambahkan ke keranjang belanja',
-      //   status: 'success',
-      //   duration: 3000,
-      //   isClosable: true,
-      //   position: 'top',
-      // });
-
-      // Redirect ke halaman checkout
-      router.push('/shop/checkout?source=buy');
+      router.push('/shop/cart');
+
     } catch (error) {
       console.error('Gagal menambahkan produk ke keranjang:', error);
+      toast.error('Terjadi kesalahan saat menambahkan produk ke keranjang');
       // setStatus('error');
     }
   };
-- 
cgit v1.2.3


From ea68149a86437bd89dfcc608d602aa194cd3b436 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 15 Aug 2025 13:43:58 +0700
Subject: <hafid> fix alur repeat order

---
 src/lib/transaction/components/Transactions.jsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'src/lib/transaction/components/Transactions.jsx')

diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx
index 2596b47f..893fbfbb 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -347,6 +347,7 @@ const Transactions = ({ context = '' }) => {
   const handleBuyBack = async (products) => {
     try {
       // setStatus('loading');
+      console.log("Products to add:", products);
 
       const results = await Promise.all(
         products.map((product) =>
@@ -356,8 +357,8 @@ const Transactions = ({ context = '' }) => {
             id: product.id,
             qty: product.quantity,
             selected: true,
-            source: 'buy',
-            qtyAppend: false,
+            source: 'add_to_cart',
+            qtyAppend: true,
           }).catch(error => {
             return { error, product };
           })
@@ -365,6 +366,7 @@ const Transactions = ({ context = '' }) => {
       );
 
       const failedOperations = results.filter(result => result && result.error);
+      console.log(results);
       
       if (failedOperations.length > 0) {
         console.error('Some products failed to add to cart:', failedOperations);
-- 
cgit v1.2.3


From d042efda0985a4a28c4484749fb0b2cd34b7bf9e Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 15 Aug 2025 13:47:56 +0700
Subject: <hafid> fix alur repeat order

---
 src/lib/transaction/components/Transactions.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'src/lib/transaction/components/Transactions.jsx')

diff --git a/src/lib/transaction/components/Transactions.jsx b/src/lib/transaction/components/Transactions.jsx
index 893fbfbb..5e37be50 100644
--- a/src/lib/transaction/components/Transactions.jsx
+++ b/src/lib/transaction/components/Transactions.jsx
@@ -366,7 +366,7 @@ const Transactions = ({ context = '' }) => {
       );
 
       const failedOperations = results.filter(result => result && result.error);
-      console.log(results);
+      // console.log(results);
       
       if (failedOperations.length > 0) {
         console.error('Some products failed to add to cart:', failedOperations);
-- 
cgit v1.2.3

