From 46496d74380c57f691f4aa33eed39d8dbaf0e916 Mon Sep 17 00:00:00 2001 From: Jaroslav Drzik Date: Tue, 19 Mar 2024 20:18:54 +0100 Subject: [PATCH] fix currency recalc --- resources/js/Layouts/GuestLayout.vue | 15 ++++++++++++++- resources/js/Pages/IkeaRoot.vue | 11 +---------- resources/js/settingsStore.js | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/resources/js/Layouts/GuestLayout.vue b/resources/js/Layouts/GuestLayout.vue index 9a55b3f..c235439 100644 --- a/resources/js/Layouts/GuestLayout.vue +++ b/resources/js/Layouts/GuestLayout.vue @@ -145,6 +145,19 @@ const fetch = async () => { } }; +function selectCurrency(item, id) { + + if (typeof countryCurrency.value[settingsStore.country.country] !== 'undefined') { + settingsStore.currency = countryCurrency.value[settingsStore.country.country]; + } else { + settingsStore.currency = "EUR"; + } + + if (settingsStore.currency != "EUR") + settingsStore.currencyCoef = currencyHash.value[settingsStore.currency]; + else settingsStore.currencyCoef = 1.0; +} + function selectCountry(item, id) { let cCntry = [["Country"]]; @@ -212,7 +225,7 @@ onMounted(fetch_menu); Country in which search product
- + diff --git a/resources/js/Pages/IkeaRoot.vue b/resources/js/Pages/IkeaRoot.vue index 312bb3f..eb09b14 100644 --- a/resources/js/Pages/IkeaRoot.vue +++ b/resources/js/Pages/IkeaRoot.vue @@ -93,7 +93,7 @@ const tproducts = computed(() => { if (prod.tag == "NONE") prod.tag = ""; prod.salesPrice = Math.round(prod.salesPrice * 100) / 100; prod.calcPrice = - Math.round(prod.calcPrice * currencyCoef.value * 100) / 100; + Math.round(prod.calcPrice * settingsStore.currencyCoef * 100) / 100; prod.rate = currencyHash.value[prod.currency]; if (prod.tag != null && prod.tag.length > 1) prod.tag = prod.tag.replace(/_/g, " "); return prod; @@ -183,7 +183,6 @@ const ccountry = ref([]); const ccountry_list = ref(["TEST"]); const currencyHash = ref({}); const currency = ref([]); -const currencyCoef = ref(1.0); const items = ref([]); @@ -387,14 +386,6 @@ const showRow = async (item) => { response.isConfirmed && fetch(); } }; -const onSelectCurrency = () => { - console.log("CURR", settingsStore.currency); - console.log("COEF", currencyCoef.value); - - if (settingsStore.currency != "EUR") - currencyCoef.value = currencyHash.value[settingsStore.currency]; - else currencyCoef.value = 1.0; -}; const submit = () => { console.log("ITEM=", form); diff --git a/resources/js/settingsStore.js b/resources/js/settingsStore.js index 4cdae25..8e7ec31 100644 --- a/resources/js/settingsStore.js +++ b/resources/js/settingsStore.js @@ -9,5 +9,6 @@ export const settingsStore = reactive({ currency: "EUR", online: false, ccountry_filter: [["Country"]], + currencyCoef: 1.0, settings: {}, });