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

Fix: Dynamic urls name should only be prefixed when appendStoreCode is true #3685

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.11.0-rc.2] - unreleased

### Fixed

- Fixed problem around dynamic urls when default storeView is set with appendStoreCode false and url set to / . @resubaka (#3685)

## [1.11.0-rc.1] - 2019.10.03

### Added
Expand Down
8 changes: 6 additions & 2 deletions core/lib/multistore.ts
Expand Up @@ -141,8 +141,11 @@ export function localizedDispatcherRoute (routeObj: LocalizedRoute | string, sto
return routeObj
}

export function localizedDispatcherRouteName (routeName: string, storeCode: string): string {
return storeCode ? `${storeCode}-${routeName}` : routeName
export function localizedDispatcherRouteName (routeName: string, storeCode: string, appendStoreCode: boolean = false): string {
if (appendStoreCode) {
return `${storeCode}-${routeName}`
}
return routeName
}

export function localizedRoute (routeObj: LocalizedRoute | string | RouteConfig | RawLocation, storeCode: string): any {
Expand Down Expand Up @@ -170,6 +173,7 @@ export function localizedRoute (routeObj: LocalizedRoute | string | RouteConfig
}

export function setupMultistoreRoutes (config, router: VueRouter, routes: RouteConfig[], priority: number = 0): void {
debugger
const allRoutes: RouteConfig[] = []
const { storeCode, appendStoreCode } = currentStoreView()
if (storeCode && appendStoreCode) {
Expand Down
4 changes: 2 additions & 2 deletions core/modules/catalog-next/store/category/actions.ts
Expand Up @@ -109,14 +109,14 @@ const actions: ActionTree<CategoryState, RootState> = {
})
},
async registerCategoryProductsMapping ({ dispatch }, products = []) {
const storeCode = currentStoreView().storeCode
const { storeCode, appendStoreCode } = currentStoreView()
await Promise.all(products.map(product => {
const { url_path, sku, slug, type_id } = product
return dispatch('url/registerMapping', {
url: localizedDispatcherRoute(url_path, storeCode),
routeData: {
params: { parentSku: product.sku, slug },
'name': localizedDispatcherRouteName(type_id + '-product', storeCode)
'name': localizedDispatcherRouteName(type_id + '-product', storeCode, appendStoreCode)
}
}, { root: true })
}))
Expand Down
4 changes: 2 additions & 2 deletions core/modules/catalog/store/category/actions.ts
Expand Up @@ -63,7 +63,7 @@ const actions: ActionTree<CategoryState, RootState> = {
return list
},
async registerCategoryMapping ({ dispatch }, { categories }) {
const storeCode = currentStoreView().storeCode
const { storeCode, appendStoreCode } = currentStoreView()
for (let category of categories) {
if (category.url_path) {
await dispatch('url/registerMapping', {
Expand All @@ -72,7 +72,7 @@ const actions: ActionTree<CategoryState, RootState> = {
params: {
'slug': category.slug
},
'name': localizedDispatcherRouteName('category', storeCode)
'name': localizedDispatcherRouteName('category', storeCode, appendStoreCode)
}
}, { root: true })
}
Expand Down
4 changes: 2 additions & 2 deletions core/modules/catalog/store/product/actions.ts
Expand Up @@ -296,7 +296,7 @@ const actions: ActionTree<ProductState, RootState> = {
return searchResult
},
preConfigureAssociated (context, { searchResult, prefetchGroupProducts }) {
const storeCode = currentStoreView().storeCode
const { storeCode, appendStoreCode } = currentStoreView()
for (let product of searchResult.items) {
if (product.url_path) {
const { parentSku, slug } = product
Expand All @@ -305,7 +305,7 @@ const actions: ActionTree<ProductState, RootState> = {
url: localizedDispatcherRoute(product.url_path, storeCode),
routeData: {
params: { parentSku, slug },
'name': localizedDispatcherRouteName(product.type_id + '-product', storeCode)
'name': localizedDispatcherRouteName(product.type_id + '-product', storeCode, appendStoreCode)
}
}, { root: true })
}
Expand Down
6 changes: 3 additions & 3 deletions core/modules/url/store/actions.ts
Expand Up @@ -66,15 +66,15 @@ export const actions: ActionTree<UrlState, any> = {
* This method could be overriden in custom module to provide custom URL mapping logic
*/
async mappingFallback ({ dispatch }, { url, params }: { url: string, params: any}) {
const storeCode = currentStoreView().storeCode
const { storeCode, appendStoreCode } = currentStoreView()
const productQuery = new SearchQuery()
url = (removeStoreCodeFromRoute(url.startsWith('/') ? url.slice(1) : url) as string)
productQuery.applyFilter({key: 'url_path', value: {'eq': url}}) // Tees category
const products = await dispatch('product/list', { query: productQuery }, { root: true })
if (products && products.items && products.items.length) {
const product = products.items[0]
return {
name: localizedDispatcherRouteName(product.type_id + '-product', storeCode),
name: localizedDispatcherRouteName(product.type_id + '-product', storeCode, appendStoreCode),
params: {
slug: product.slug,
parentSku: product.sku,
Expand All @@ -85,7 +85,7 @@ export const actions: ActionTree<UrlState, any> = {
const category = await dispatch('category/single', { key: 'url_path', value: url }, { root: true })
if (category !== null) {
return {
name: localizedDispatcherRouteName('category', storeCode),
name: localizedDispatcherRouteName('category', storeCode, appendStoreCode),
params: {
slug: category.slug
}
Expand Down