@scayle/storefront-nuxt
Version:
Nuxt integration for the SCAYLE Commerce Engine and Storefront API
22 lines (21 loc) • 785 B
JavaScript
import { defineNuxtPlugin } from "nuxt/app";
import { useCurrentShop } from "../composables/core/useCurrentShop.js";
import { useAvailableShops } from "../composables/core/useAvailableShops.js";
export default defineNuxtPlugin((nuxtApp) => {
const currentShop = useCurrentShop();
const availableShops = useAvailableShops();
if (import.meta.server && nuxtApp.ssrContext) {
if (nuxtApp.ssrContext.event.context.$currentShop) {
currentShop.value = nuxtApp.ssrContext.event.context.$currentShop;
}
if (nuxtApp.ssrContext.event.context.$availableShops) {
availableShops.value = nuxtApp.ssrContext.event.context.$availableShops;
}
}
return {
provide: {
currentShop: currentShop.value,
availableShops: availableShops.value
}
};
});