diff --git a/components/CurrentPageMixin.ts b/components/CurrentPageMixin.ts new file mode 100644 index 0000000..f7bb443 --- /dev/null +++ b/components/CurrentPageMixin.ts @@ -0,0 +1,39 @@ +import { isServer } from '@vue-storefront/core/helpers' +import { RouterManager } from '@vue-storefront/core/lib/router-manager' + +export default { + data () { + return { + currentRouteComponentName: null + } + }, + watch: { + '$route': function () { + this.setCurrentPage() + } + }, + computed: { + isProductPage () { + return this.currentRouteComponentName == 'Product' + }, + isCategoryPage () { + return this.currentRouteComponentName == 'Category' + }, + isStoryblokPage () { + return this.currentRouteComponentName == 'StoryblokPage' + }, + isCheckoutPage () { + return this.currentRouteComponentName == 'Checkout' + }, + }, + created () { + this.setCurrentPage() + }, + methods: { + setCurrentPage () { + const route = RouterManager.findByName(this.$route.name) + console.log({pageType: route.component.name}) + this.currentRouteComponentName = route && route.component && route.component.name + } + } +} diff --git a/components/SharedMixin.ts b/components/SharedMixin.ts index d04d881..d5b1967 100644 --- a/components/SharedMixin.ts +++ b/components/SharedMixin.ts @@ -5,10 +5,12 @@ import { localizedRoute, removeStoreCodeFromRoute } from '@vue-storefront/core/l import get from 'lodash.get' import StoryblokMixin from 'src/modules/vsf-storyblok-module/components/StoryblokMixin' import config from 'config' +import CurrentPageMixin from './CurrentPageMixin' +import { findCategoryByPath } from '../findCategoryByPath' export default { name: 'StorePickerMixin', - mixins: [StoryblokMixin], + mixins: [StoryblokMixin, CurrentPageMixin], computed: { ...mapGetters({ current: 'store-picker/currentStoreView', @@ -27,7 +29,13 @@ export default { } // Are we on a Storyblok CMS page? - if(this.story && !this.story.full_slug.endsWith('/home')){ + if (this.isProductPage) { + return this.localizedRoute(url, view).replace(/\/$/, "") + '?posterpage' + } + else if (this.isCategoryPage) { + return this.localizedRoute(url, view).replace(/\/$/, "") + '?categorypage' + } + else if (this.isStoryblokPage && !this.story.full_slug.endsWith('/home')){ // Try to find an alternate story for the target storeview let alternateStory = this.story.alternates.find((alternate) => { return alternate.full_slug.startsWith(view.storeCode + '/')