From e4b4f2c09ebd819acc204c2e58288fe9fc6294ea Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Thu, 15 Jun 2023 15:45:43 +0700 Subject: get dan delete cart --- src/core/utils/cart.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/core/utils/cart.js') 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 } -- cgit v1.2.3 From 637c22f1886cecf7307ced88dc951134d466a3fa Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Mon, 19 Jun 2023 15:46:03 +0700 Subject: checkout --- src/core/utils/cart.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/core/utils/cart.js') diff --git a/src/core/utils/cart.js b/src/core/utils/cart.js index ad7894b5..6575f6d0 100644 --- a/src/core/utils/cart.js +++ b/src/core/utils/cart.js @@ -14,13 +14,6 @@ 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. * @@ -51,6 +44,22 @@ const addCart = async (product_id, qty, selected) => { ) } +const getCartApi = async () => { + const id = getAuth()?.id + const cart = await odooApi('GET', `/api/v1/user/${id}/cart`) + + return cart +} + +const getCountCart = async () => { + const id = getAuth()?.id + if(id){ + const cart = await odooApi('GET', `/api/v1/user/${id}/cart/count`) + return cart + } + return +} + const deleteCart = async (product_id) => { const id = getAuth()?.id const cartDelete = await odooApi( @@ -85,7 +94,7 @@ const updateItemCart = ({ productId, quantity, selected = false }) => { quantity = parseInt(quantity) cart[productId] = { productId, quantity, selected } setCart(cart) - addCart(productId, quantity) + addCart(productId, quantity, selected) return true } @@ -104,4 +113,4 @@ const deleteItemCart = ({ productId }) => { return true } -export { getCart, getItemCart, updateItemCart, deleteItemCart, getCartnew } +export { getCart, getItemCart, updateItemCart, deleteItemCart, addCart, getCartApi, getCountCart} -- cgit v1.2.3 From 84ae09f61f05f212ec098da1fd4ed14960119527 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Tue, 27 Jun 2023 09:07:22 +0700 Subject: promotion detail --- src/core/utils/cart.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/core/utils/cart.js') diff --git a/src/core/utils/cart.js b/src/core/utils/cart.js index 6575f6d0..eb411dd3 100644 --- a/src/core/utils/cart.js +++ b/src/core/utils/cart.js @@ -30,12 +30,17 @@ const setCart = (cart) => { return false } -const addCart = async (product_id, qty, selected) => { +const addCart = async (product_id, qty, selected, programLineId = null) => { const data = { 'product_id' : product_id, 'qty' : qty, 'selected' : selected, } + if(programLineId){ + data += { + 'program_line_id' : programLineId, + } + } const id = getAuth()?.id const cartAdd = await odooApi( 'POST', @@ -89,12 +94,12 @@ const getItemCart = ({ productId }) => { * @param {boolean} [options.selected=false] - The new selected status of the product in the cart. Default is `false`. * @returns {boolean} - Returns `true`. */ -const updateItemCart = ({ productId, quantity, selected = false }) => { +const updateItemCart = ({ productId, quantity, selected = false , programLineId}) => { let cart = getCart() quantity = parseInt(quantity) cart[productId] = { productId, quantity, selected } setCart(cart) - addCart(productId, quantity, selected) + addCart(productId, quantity, selected, programLineId) return true } -- cgit v1.2.3 From c4ff871551cfbf3ed759b3d7be735d7039edb6f5 Mon Sep 17 00:00:00 2001 From: "HATEC\\SPVDEV001" Date: Fri, 30 Jun 2023 14:58:05 +0700 Subject: cart --- src/core/utils/cart.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/core/utils/cart.js') diff --git a/src/core/utils/cart.js b/src/core/utils/cart.js index eb411dd3..16befdf7 100644 --- a/src/core/utils/cart.js +++ b/src/core/utils/cart.js @@ -35,18 +35,18 @@ const addCart = async (product_id, qty, selected, programLineId = null) => { 'product_id' : product_id, 'qty' : qty, 'selected' : selected, + 'program_line_id' : programLineId } - if(programLineId){ - data += { - 'program_line_id' : programLineId, - } - } + const id = getAuth()?.id const cartAdd = await odooApi( 'POST', `/api/v1/user/${id}/cart/create-or-update`, data ) + + return true + } const getCartApi = async () => { @@ -94,12 +94,12 @@ const getItemCart = ({ productId }) => { * @param {boolean} [options.selected=false] - The new selected status of the product in the cart. Default is `false`. * @returns {boolean} - Returns `true`. */ -const updateItemCart = ({ productId, quantity, selected = false , programLineId}) => { +const updateItemCart = async ({ productId, quantity, selected = false , programLineId}) => { let cart = getCart() quantity = parseInt(quantity) cart[productId] = { productId, quantity, selected } setCart(cart) - addCart(productId, quantity, selected, programLineId) + await addCart(productId, quantity, selected, programLineId) return true } -- cgit v1.2.3