3636 >
3737 {{ cartLength }}
3838 </span >
39- <span class =" text-white lg:text-black" >Total: {{ subTotal }}</span >
39+ <span class =" text-white lg:text-black"
40+ >Total: {{ config.currencySymbol }} {{ subTotal }}</span
41+ >
4042 </div >
4143 </transition >
4244 </NuxtLink >
@@ -49,10 +51,16 @@ import GET_CART_QUERY from "@/apollo/queries/GET_CART_QUERY.gql";
4951
5052import { getCookie } from " @/utils/functions" ;
5153
54+ import { useCart } from " @/store/useCart" ;
55+
5256const cartLength = useState (" cartLength" , () => 0 );
5357const subTotal = useState (" subTotal" , " " );
5458const remoteError = useState (" remoteError" , () => false );
5559
60+ const config = useRuntimeConfig ();
61+
62+ const cart = useCart ();
63+
5664const { data , error , pending , execute } = await useAsyncQuery (GET_CART_QUERY , {
5765 options: { fetchPolicy: " cache-and-network" },
5866});
@@ -62,22 +70,21 @@ const updateCartDisplay = () => {
6270 return ;
6371 }
6472
65- cartLength .value = data .value .cart .contents .nodes .reduce (
66- (accumulator , argument ) => accumulator + argument .quantity ,
67- 0
68- );
73+ cartLength .value = cart .getCartQuantity ;
6974
70- subTotal .value = data . value . cart .total ;
75+ subTotal .value = cart .getCartTotal ;
7176
7277 remoteError .value = error;
7378};
7479
75- onMounted (() => updateCartDisplay ());
80+ onBeforeMount (() => {
81+ execute ();
82+ updateCartDisplay ();
83+ });
7684
7785setInterval (() => {
7886 if (process .client && ! pending .value && getCookie (" woo-session" )) {
79- execute ();
8087 updateCartDisplay ();
8188 }
82- }, 3000 );
89+ }, 1000 );
8390 </script >
0 commit comments