diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/helpers/apiOdoo.js | 2 | ||||
| -rw-r--r-- | src/helpers/cart.js | 9 | ||||
| -rw-r--r-- | src/pages/shop/cart.js | 9 | ||||
| -rw-r--r-- | src/pages/shop/product/[slug].js | 2 |
4 files changed, 9 insertions, 13 deletions
diff --git a/src/helpers/apiOdoo.js b/src/helpers/apiOdoo.js index 8009a302..22fd1920 100644 --- a/src/helpers/apiOdoo.js +++ b/src/helpers/apiOdoo.js @@ -27,7 +27,7 @@ const apiOdoo = async (method, url, data = {}, headers = {}) => { if (Object.keys(data).length > 0) axiosParameter.data = new URLSearchParams(Object.entries(data)).toString(); let res = await axios(axiosParameter); - if (res.data.status.code == 401 && connectionTry <= 3) { + if (res.data.status.code == 401 && connectionTry < 15) { await renewToken(); return apiOdoo(method, url, data, headers); } diff --git a/src/helpers/cart.js b/src/helpers/cart.js index 8712c03a..2cd8da7b 100644 --- a/src/helpers/cart.js +++ b/src/helpers/cart.js @@ -14,14 +14,9 @@ const getItemCart = (product_id) => { return cart[product_id]; } -const createOrUpdateItemCart = (product_id, quantity) => { +const createOrUpdateItemCart = (product_id, quantity, to_process = false) => { let cart = getCart(); - let isFoundInCart = cart[product_id]; - if (isFoundInCart) { - cart[product_id].quantity = quantity; - } else { - cart[product_id] = { product_id, quantity }; - } + cart[product_id] = { product_id, quantity, to_process }; setCart(cart); return true; } 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>'); |
