From ce8dcaac9cf066e51a1f2faaef517b4bed4ae612 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 15:43:40 +0200 Subject: [PATCH 1/3] Fix: Dynamic urls name should only be prefixed when appendStoreCode is true This is a fix for when you have the baseStore set to an storeView store for example de and have appendStoreCode false and url as /. Then it currently does not work when multistore is active. With this is does work as the base url is now the de store with no prefix in the dynamic url name. --- core/lib/multistore.ts | 8 ++++++-- core/modules/catalog-next/store/category/actions.ts | 4 ++-- core/modules/catalog/store/category/actions.ts | 4 ++-- core/modules/catalog/store/product/actions.ts | 4 ++-- core/modules/url/store/actions.ts | 6 +++--- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/core/lib/multistore.ts b/core/lib/multistore.ts index e0b1244245..22ef790291 100644 --- a/core/lib/multistore.ts +++ b/core/lib/multistore.ts @@ -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 { @@ -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) { diff --git a/core/modules/catalog-next/store/category/actions.ts b/core/modules/catalog-next/store/category/actions.ts index b9de48da1d..5a1a9a5f8e 100644 --- a/core/modules/catalog-next/store/category/actions.ts +++ b/core/modules/catalog-next/store/category/actions.ts @@ -109,14 +109,14 @@ const actions: ActionTree = { }) }, 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 }) })) diff --git a/core/modules/catalog/store/category/actions.ts b/core/modules/catalog/store/category/actions.ts index a98f491cd6..9ac14abc9f 100644 --- a/core/modules/catalog/store/category/actions.ts +++ b/core/modules/catalog/store/category/actions.ts @@ -63,7 +63,7 @@ const actions: ActionTree = { 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', { @@ -72,7 +72,7 @@ const actions: ActionTree = { params: { 'slug': category.slug }, - 'name': localizedDispatcherRouteName('category', storeCode) + 'name': localizedDispatcherRouteName('category', storeCode, appendStoreCode) } }, { root: true }) } diff --git a/core/modules/catalog/store/product/actions.ts b/core/modules/catalog/store/product/actions.ts index 46e9b99590..49fd45011d 100644 --- a/core/modules/catalog/store/product/actions.ts +++ b/core/modules/catalog/store/product/actions.ts @@ -296,7 +296,7 @@ const actions: ActionTree = { 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 @@ -305,7 +305,7 @@ const actions: ActionTree = { 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 }) } diff --git a/core/modules/url/store/actions.ts b/core/modules/url/store/actions.ts index 66568ccd9f..cb59ae9ca5 100644 --- a/core/modules/url/store/actions.ts +++ b/core/modules/url/store/actions.ts @@ -66,7 +66,7 @@ export const actions: ActionTree = { * 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 @@ -74,7 +74,7 @@ export const actions: ActionTree = { 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, @@ -85,7 +85,7 @@ export const actions: ActionTree = { 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 } From a57d00bc6f8d1c45072c72d0f914fa72e5179b5b Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 15:50:29 +0200 Subject: [PATCH 2/3] Updated CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c64949d845..d4da8db453 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 6f9d6cb98468cbfbbf1487a4f9d245ce02301588 Mon Sep 17 00:00:00 2001 From: ResuBaka Date: Fri, 4 Oct 2019 15:53:39 +0200 Subject: [PATCH 3/3] removed debugger --- core/lib/multistore.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/core/lib/multistore.ts b/core/lib/multistore.ts index 22ef790291..249b45ee51 100644 --- a/core/lib/multistore.ts +++ b/core/lib/multistore.ts @@ -173,7 +173,6 @@ 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) {