Skip to content

Commit f0dc4b2

Browse files
committed
Currency symbol as .env variable
1 parent 5b0c51b commit f0dc4b2

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PUBLIC_GRAPHQL_URL = "change me"
22
PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL = "https://via.placeholder.com/500"
3+
PUBLIC_CURRENCY_SYMBOL = "kr"
34
ALGOLIA_APPLICATION_ID = "change me"
45
ALGOLIA_API_KEY = "change me"
56
ALGOLIA_INDEX_NAME = "change me"

components/Layout/LayoutCart.vue

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
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>
@@ -55,6 +57,8 @@ const cartLength = useState("cartLength", () => 0);
5557
const subTotal = useState("subTotal", "");
5658
const remoteError = useState("remoteError", () => false);
5759
60+
const config = useRuntimeConfig();
61+
5862
const cart = useCart();
5963
6064
const { data, error, pending, execute } = await useAsyncQuery(GET_CART_QUERY, {
@@ -66,20 +70,10 @@ const updateCartDisplay = () => {
6670
return;
6771
}
6872
69-
/*cartLength.value = data.value.cart.contents.nodes.reduce(
70-
(accumulator, argument) => accumulator + argument.quantity,
71-
0
72-
);
73-
*/
74-
7573
cartLength.value = cart.getCartQuantity;
7674
7775
subTotal.value = cart.getCartTotal;
7876
79-
console.log("Pinia total: ", cart.getCartTotal);
80-
81-
//subTotal.value = data.value.cart.total;
82-
8377
remoteError.value = error;
8478
};
8579
@@ -90,8 +84,7 @@ onBeforeMount(() => {
9084
9185
setInterval(() => {
9286
if (process.client && !pending.value && getCookie("woo-session")) {
93-
//execute();
9487
updateCartDisplay();
9588
}
96-
}, 3000);
89+
}, 2000);
9790
</script>

components/Products/ProductsSingleProduct.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ const addProductToCart = async (product) => {
111111
112112
const addToCartvariables = { input: productQueryInput };
113113
114-
console.log("Should add cart to product:", product);
115114
cart.addToCart(product);
116-
117115
118116
const { mutate, onDone, onError } = useMutation(ADD_TO_CART_MUTATION, {
119117
addToCartvariables,

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default defineNuxtConfig({
2020
graphqlURL: process.env.PUBLIC_GRAPHQL_URL,
2121
indexName: process.env.PUBLIC_ALGOLIA_INDEX_NAME,
2222
placeholderImage: process.env.PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL,
23+
currencySymbol: process.env.PUBLIC_CURRENCY_SYMBOL,
2324
},
2425
},
2526
postcss: {

store/useCart.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ export const useCart = defineStore("cartState", {
6060
return this.customer;
6161
},
6262
getCartTotal() {
63+
const currencySymbol = useRuntimeConfig().public.currencySymbol || "kr";
64+
6365
return this.cart.reduce(
64-
(total, product) => total + product.price * product.quantity,
66+
(total, product) =>
67+
total +
68+
Number(product.price.replace(currencySymbol, "")) * product.quantity,
6569
0
6670
);
6771
},

0 commit comments

Comments
 (0)