diff options
| author | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-26 17:07:40 +0700 |
|---|---|---|
| committer | Rafi Zadanly <rafizadanly@gmail.com> | 2022-12-26 17:07:40 +0700 |
| commit | 1e12cbcedbb8eaf52982cef89e35a29b0e555537 (patch) | |
| tree | 8409ab9f0606491ac7d3b8d4d5bbc8a40fccd90f /src/pages/shop | |
| parent | f2dad674f9096ca2423cbbdc0228576f094f064c (diff) | |
save state cart to process
Diffstat (limited to 'src/pages/shop')
| -rw-r--r-- | src/pages/shop/cart.js | 9 | ||||
| -rw-r--r-- | src/pages/shop/product/[slug].js | 2 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/pages/shop/cart.js b/src/pages/shop/cart.js index f099a19e..452289b4 100644 --- a/src/pages/shop/cart.js +++ b/src/pages/shop/cart.js @@ -24,7 +24,6 @@ import Layout from "../../components/Layout"; import Link from "../../components/Link"; import Alert from "../../components/Alert"; import Spinner from "../../components/Spinner"; -import { useRouter } from "next/router"; import AppBar from "../../components/AppBar"; export default function Cart() { @@ -47,7 +46,7 @@ export default function Cart() { dataProducts = dataProducts.map((product) => ({ ...product, quantity: cart[product.id].quantity, - to_process: false + to_process: cart[product.id].to_process, })); setProducts(dataProducts); } @@ -59,6 +58,9 @@ export default function Cart() { }, []); useEffect(() => { + for (const product of products) { + if (product.quantity != '') createOrUpdateItemCart(product.id, product.quantity, product.to_process); + } const productsToProcess = products.filter((product) => product.to_process == true); let calculateTotalPriceBeforeTax = 0; let calculateTotalTaxAmount = 0; @@ -80,7 +82,6 @@ export default function Cart() { const updateCart = (productId, quantity) => { let productIndexToUpdate = products.findIndex((product) => product.id == productId); - if (quantity != '') createOrUpdateItemCart(productId, quantity); let productsToUpdate = products; productsToUpdate[productIndexToUpdate].quantity = quantity; setProducts([...productsToUpdate]); @@ -321,7 +322,7 @@ export default function Cart() { className="flex-1 btn-yellow" disabled={getProductsToProcess().length == 0} > - Bayar {getProductsToProcess().length > 0 ? `(${getProductsToProcess().length})` : ''} + Checkout {getProductsToProcess().length > 0 ? `(${getProductsToProcess().length})` : ''} </button> </div> ) : ''} diff --git a/src/pages/shop/product/[slug].js b/src/pages/shop/product/[slug].js index 5913f17d..b76cdee9 100644 --- a/src/pages/shop/product/[slug].js +++ b/src/pages/shop/product/[slug].js @@ -18,7 +18,7 @@ export async function getServerSideProps( context ) { if (product.length == 1) { product = product[0]; product.description = product.description.replaceAll('<p>', '||p||'); - product.description = product.description.replaceAll('</>', '||/p||'); + product.description = product.description.replaceAll('</p>', '||/p||'); product.description = product.description.replace(/(<([^>]+)>)/gi, ' '); product.description = product.description.replaceAll('||p||', '<p>'); product.description = product.description.replaceAll('||/p||', '</p>'); |
