Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CurrentPageMixin.ts #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions components/CurrentPageMixin.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}
12 changes: 10 additions & 2 deletions components/SharedMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 + '/')
Expand Down