-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
118 lines (100 loc) · 3.34 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<script setup lang="ts">
import { getPrefix } from "./i18n/src/helpers/prefix";
import type { Schemas } from "#shopware";
/**
* Init breadcrumbs context
*/
useBreadcrumbs();
useHead({
title: "Shopware Demo store",
meta: [{ name: "description", content: "Shopware Demo store" }],
htmlAttrs: {
lang: "en",
},
});
const { apiClient } = useShopwareContext();
const sessionContextData = ref<Schemas["SalesChannelContext"]>();
sessionContextData.value = await apiClient.invoke("readContext get /context");
// If you enable runtimeConfig.shopware.useUserContextInSSR, then you can use this code to share session between server and client.
// const { data: sessionContextData } = await useAsyncData(
// "sessionContext",
// async () => {
// return await getSessionContext(apiInstance);
// }
// );
// read the locale/lang code from accept-language header (i.e. en, en-GB or de-DE)
// and set configuration for price formatting globally
const headers = useRequestHeaders();
// Extract the first (with highest priority order) locale or lang code from accept-language header
// for example: "en-US;q=0.7,en;q=0.3" will return "en-US"
const localeFromHeader = headers?.["accept-language"]
?.split(",")
?.map(
(languageConfig) => languageConfig.match(/^([a-z]{2}(?:-[A-Z]{2})?)/)?.[0],
)
.find(Boolean);
usePrice({
currencyCode: sessionContextData.value?.currency?.isoCode || "",
localeCode: localeFromHeader,
});
useSessionContext(sessionContextData.value);
const { getWishlistProducts } = useWishlist();
const { refreshCart } = useCart();
useNotifications();
useAddress();
const { locale, availableLocales, defaultLocale } = useI18n();
const router = useRouter();
const {
getAvailableLanguages,
getLanguageCodeFromId,
getLanguageIdFromCode,
changeLanguage,
languages: storeLanguages,
} = useInternationalization();
const { languageIdChain, refreshSessionContext } = useSessionContext();
const { data: languages } = await useAsyncData("languages", async () => {
return await getAvailableLanguages();
});
if (languages.value?.elements.length && router.currentRoute.value.name) {
storeLanguages.value = languages.value?.elements;
// Prefix from url
const prefix = getPrefix(
availableLocales,
router.currentRoute.value.name as string,
defaultLocale,
);
// Language set on the backend side
const sessionLanguage = getLanguageCodeFromId(languageIdChain.value);
// If languages are not the same, set one from prefix
if (sessionLanguage !== prefix) {
await changeLanguage(
getLanguageIdFromCode(prefix ? prefix : defaultLocale),
);
await refreshSessionContext();
}
locale.value = prefix ? prefix : defaultLocale;
// Set prefix from CMS components
provide("urlPrefix", prefix);
}
onMounted(() => {
refreshCart();
getWishlistProducts();
});
</script>
<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>
<style>
h2 {
@apply text-4xl py-4;
}
select {
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIGZpbGw9J25vbmUnIHZpZXdCb3g9JzAgMCAyMCAyMCc+PHBhdGggc3Ryb2tlPScjNmI3MjgwJyBzdHJva2UtbGluZWNhcD0ncm91bmQnIHN0cm9rZS1saW5lam9pbj0ncm91bmQnIHN0cm9rZS13aWR0aD0nMS41JyBkPSdNNiA4bDQgNCA0LTQnLz48L3N2Zz4=");
background-position: right 0.5rem center;
background-repeat: no-repeat;
background-size: 1.5em 1.5em;
appearance: none;
}
</style>