diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-06-15 15:45:43 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-06-15 15:45:43 +0700 |
| commit | e4b4f2c09ebd819acc204c2e58288fe9fc6294ea (patch) | |
| tree | a22399091ca0e4f35948ddcb58b2321d26c4c4c2 /src/core/utils | |
| parent | eb4ae7be05ed97bd02b7f3e9cc56393f435188e2 (diff) | |
get dan delete cart
Diffstat (limited to 'src/core/utils')
| -rw-r--r-- | src/core/utils/cart.js | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/core/utils/cart.js b/src/core/utils/cart.js index d987cda7..ad7894b5 100644 --- a/src/core/utils/cart.js +++ b/src/core/utils/cart.js @@ -1,3 +1,6 @@ +import odooApi from "../api/odooApi" +import { getAuth } from "./auth" + /** * Retrieves cart data from localStorage, if available. * @@ -11,6 +14,13 @@ const getCart = () => { return {} } +const getCartnew = async () => { + const id = getAuth()?.id + const cart = await odooApi('GET', `/api/v1/user/${id}/cart`) + + return cart +} + /** * Saves cart data to localStorage, if available. * @@ -27,6 +37,28 @@ const setCart = (cart) => { return false } +const addCart = async (product_id, qty, selected) => { + const data = { + 'product_id' : product_id, + 'qty' : qty, + 'selected' : selected, + } + const id = getAuth()?.id + const cartAdd = await odooApi( + 'POST', + `/api/v1/user/${id}/cart/create-or-update`, + data + ) +} + +const deleteCart = async (product_id) => { + const id = getAuth()?.id + const cartDelete = await odooApi( + 'DELETE', + `/api/v1/user/${id}/cart?product_ids=${product_id}` + ) +} + /** * Retrieves an item from the cart data based on the given product ID. * @@ -53,6 +85,7 @@ const updateItemCart = ({ productId, quantity, selected = false }) => { quantity = parseInt(quantity) cart[productId] = { productId, quantity, selected } setCart(cart) + addCart(productId, quantity) return true } @@ -66,8 +99,9 @@ const updateItemCart = ({ productId, quantity, selected = false }) => { const deleteItemCart = ({ productId }) => { let cart = getCart() delete cart[productId] + deleteCart(productId) setCart(cart) return true } -export { getCart, getItemCart, updateItemCart, deleteItemCart } +export { getCart, getItemCart, updateItemCart, deleteItemCart, getCartnew } |
