summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/components/elements/Navbar/NavbarDesktop.jsx8
-rw-r--r--src/core/utils/cart.js27
2 files changed, 24 insertions, 11 deletions
diff --git a/src/core/components/elements/Navbar/NavbarDesktop.jsx b/src/core/components/elements/Navbar/NavbarDesktop.jsx
index 26edd5a4..733f5422 100644
--- a/src/core/components/elements/Navbar/NavbarDesktop.jsx
+++ b/src/core/components/elements/Navbar/NavbarDesktop.jsx
@@ -13,7 +13,7 @@ import Category from '@/lib/category/components/Category'
import { useEffect, useState } from 'react'
import useAuth from '@/core/hooks/useAuth'
import NavbarUserDropdown from './NavbarUserDropdown'
-import { getCart } from '@/core/utils/cart'
+import { getCountCart } from '@/core/utils/cart'
import TopBanner from './TopBanner'
import whatsappUrl from '@/core/utils/whatsappUrl'
@@ -27,7 +27,11 @@ const NavbarDesktop = () => {
useEffect(() => {
const handleCartChange = () => {
- setCartCount(Object.keys(getCart()).length)
+ const cart = async () => {
+ const listCart = await getCountCart()
+ setCartCount(listCart)
+ }
+ cart()
}
handleCartChange()
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}