From 729b54ca1a9045c6a70b94433906ece1ecb2436e Mon Sep 17 00:00:00 2001 From: Arina Yakovenko Date: Wed, 1 Apr 2026 10:52:08 +0200 Subject: [PATCH] fix: currency/county --- bo/components.d.ts | 7 +- bo/src/components/TopBar.vue | 76 ++++++++++--------- bo/src/components/TopBarLogin.vue | 4 +- bo/src/components/admin/PageProducts.vue | 2 +- bo/src/components/customer/PageProducts.vue | 2 +- .../{categoryMenu.vue => CategoryMenu.vue} | 0 .../inner/CountryCurrencySwitch.vue | 68 +++++++++++++++++ .../inner/{langSwitch.vue => LangSwitch.vue} | 0 .../{themeSwitch.vue => ThemeSwitch.vue} | 0 bo/src/plugins/02_i18n.ts | 3 +- bo/src/router/langs.ts | 31 +++++++- bo/src/types/lang.d.ts | 17 +++++ 12 files changed, 161 insertions(+), 49 deletions(-) rename bo/src/components/inner/{categoryMenu.vue => CategoryMenu.vue} (100%) create mode 100644 bo/src/components/inner/CountryCurrencySwitch.vue rename bo/src/components/inner/{langSwitch.vue => LangSwitch.vue} (100%) rename bo/src/components/inner/{themeSwitch.vue => ThemeSwitch.vue} (100%) diff --git a/bo/components.d.ts b/bo/components.d.ts index 51b00ed..5f92a0b 100644 --- a/bo/components.d.ts +++ b/bo/components.d.ts @@ -12,13 +12,14 @@ export {} declare module 'vue' { export interface GlobalComponents { CartDetails: typeof import('./src/components/customer/CartDetails.vue')['default'] - CategoryMenu: typeof import('./src/components/inner/categoryMenu.vue')['default'] + CategoryMenu: typeof import('./src/components/inner/CategoryMenu.vue')['default'] CategoryMenuListing: typeof import('./src/components/inner/categoryMenuListing.vue')['default'] + CountryCurrencySwitch: typeof import('./src/components/inner/CountryCurrencySwitch.vue')['default'] Cs_PrivacyPolicyView: typeof import('./src/components/terms/cs_PrivacyPolicyView.vue')['default'] Cs_TermsAndConditionsView: typeof import('./src/components/terms/cs_TermsAndConditionsView.vue')['default'] En_PrivacyPolicyView: typeof import('./src/components/terms/en_PrivacyPolicyView.vue')['default'] En_TermsAndConditionsView: typeof import('./src/components/terms/en_TermsAndConditionsView.vue')['default'] - LangSwitch: typeof import('./src/components/inner/langSwitch.vue')['default'] + LangSwitch: typeof import('./src/components/inner/LangSwitch.vue')['default'] PageAddresses: typeof import('./src/components/customer/PageAddresses.vue')['default'] PageCarts: typeof import('./src/components/customer/PageCarts.vue')['default'] PageOrders: typeof import('./src/components/customer/PageOrders.vue')['default'] @@ -34,7 +35,7 @@ declare module 'vue' { ProductVariants: typeof import('./src/components/customer/components/ProductVariants.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] - ThemeSwitch: typeof import('./src/components/inner/themeSwitch.vue')['default'] + ThemeSwitch: typeof import('./src/components/inner/ThemeSwitch.vue')['default'] TopBar: typeof import('./src/components/TopBar.vue')['default'] TopBarLogin: typeof import('./src/components/TopBarLogin.vue')['default'] UAlert: typeof import('./node_modules/@nuxt/ui/dist/runtime/components/Alert.vue')['default'] diff --git a/bo/src/components/TopBar.vue b/bo/src/components/TopBar.vue index 38571bd..6f15a2f 100644 --- a/bo/src/components/TopBar.vue +++ b/bo/src/components/TopBar.vue @@ -1,13 +1,49 @@ + + - - diff --git a/bo/src/components/TopBarLogin.vue b/bo/src/components/TopBarLogin.vue index 7382dc8..d1820b9 100644 --- a/bo/src/components/TopBarLogin.vue +++ b/bo/src/components/TopBarLogin.vue @@ -1,6 +1,6 @@ diff --git a/bo/src/components/inner/langSwitch.vue b/bo/src/components/inner/LangSwitch.vue similarity index 100% rename from bo/src/components/inner/langSwitch.vue rename to bo/src/components/inner/LangSwitch.vue diff --git a/bo/src/components/inner/themeSwitch.vue b/bo/src/components/inner/ThemeSwitch.vue similarity index 100% rename from bo/src/components/inner/themeSwitch.vue rename to bo/src/components/inner/ThemeSwitch.vue diff --git a/bo/src/plugins/02_i18n.ts b/bo/src/plugins/02_i18n.ts index ae41822..ca1ef5b 100644 --- a/bo/src/plugins/02_i18n.ts +++ b/bo/src/plugins/02_i18n.ts @@ -1,11 +1,12 @@ import { useFetchJson } from '@/composable/useFetchJson' -import { initLangs, langs } from '@/router/langs' +import { initCountryCurrency, initLangs, langs } from '@/router/langs' import { watch } from 'vue' import { createI18n, type PathValue } from 'vue-i18n' // const x = await initLangs() +await initCountryCurrency() export const i18ninstall = createI18n({ legacy: false, // you must set `false`, to use Composition API locale: 'en', diff --git a/bo/src/router/langs.ts b/bo/src/router/langs.ts index 520516f..54a965c 100644 --- a/bo/src/router/langs.ts +++ b/bo/src/router/langs.ts @@ -1,12 +1,16 @@ import { useCookie } from "@/composable/useCookie" import { useFetchJson } from "@/composable/useFetchJson" -import type { Language } from "@/types" +import type { Country, Language } from "@/types" import { reactive, ref } from "vue" export const langs = reactive([] as Language[]) export const currentLang = ref() -const deflang = ref() +export const countries = reactive([] as Country[]) +export const currentCountry = ref() + +const defLang = ref() +const defCountry = ref() const cookie = useCookie() // Get available language codes for route matching // export const availableLocales = computed(() => langs.map((l) => l.lang_code)) @@ -22,8 +26,27 @@ export async function initLangs() { if (cc) { idfromcookie = langs.find((x) => x.id == parseInt(cc)) } - deflang.value = items.find((x) => x.is_default == true) - currentLang.value = idfromcookie ?? deflang.value + defLang.value = items.find((x) => x.is_default == true) + currentLang.value = idfromcookie ?? defLang.value + } catch (error) { + console.error('Failed to fetch languages:', error) + } +} + +// Initialize country/currency from API + +export async function initCountryCurrency() { + try { + const { items } = await useFetchJson('/api/v1/restricted/langs-and-countries/get-countries') + countries.push(...items) + + let idfromcookie = null + const cc = cookie.getCookie('country_id') + if (cc) { + idfromcookie = langs.find((x) => x.id == parseInt(cc)) + } + defCountry.value = items.find((x) => x.id === defLang.value?.id) + currentCountry.value = idfromcookie ?? defCountry.value } catch (error) { console.error('Failed to fetch languages:', error) } diff --git a/bo/src/types/lang.d.ts b/bo/src/types/lang.d.ts index 4ee9e08..b21a3e4 100644 --- a/bo/src/types/lang.d.ts +++ b/bo/src/types/lang.d.ts @@ -12,3 +12,20 @@ export interface Language { active: boolean flag: string } + +export interface Country { + id: number + name: string + flag: string + currency_id: string + ps_currency: { + id_currency: string + name: string + iso_code: string + numeric_iso_code: string + precision: number + conversion_rate: number + deleted: boolean + active: boolean + } +}