diff --git a/config/default.json b/config/default.json index 46340b89f3..226f60f0d5 100644 --- a/config/default.json +++ b/config/default.json @@ -77,7 +77,7 @@ "twoStageCaching": true, "optimizeShoppingCart": true, "category": { - "includeFields": [ "children_data", "id", "children_count", "sku", "name", "is_active", "parent_id", "level", "url_key", "product_count" ] + "includeFields": [ "children_data", "id", "children_count", "sku", "name", "is_active", "parent_id", "level", "url_key", "product_count", "path"] }, "attribute": { "includeFields": [ "attribute_code", "id", "entity_type_id", "options", "default_value", "is_user_defined", "frontend_label", "attribute_id", "default_frontend_label", "is_visible_on_front", "is_visible", "is_comparable", "tier_prices" ] diff --git a/core/store/modules/product/actions.ts b/core/store/modules/product/actions.ts index 632b50a90f..0b6176da6d 100644 --- a/core/store/modules/product/actions.ts +++ b/core/store/modules/product/actions.ts @@ -44,36 +44,43 @@ const actions: ActionTree = { } context.state.breadcrumbs.routes = breadCrumbRoutes(path) // TODO: change to store.commit call? } - // TODO: Fix it when product is enterd from outside the category page - let currentPath = context.rootState.category.current_path - let currentCat = context.rootState.category.current - if (currentPath.length > 0 && currentCat) { - setbrcmb(currentPath) - } else { - if (product.category && product.category.length > 0) { - subloaders.push( - context.dispatch('category/list', {}, { root: true }).then((categories) => { - for (let cat of product.category.reverse()) { - let category = categories.items.find((itm) => { return itm['id'] === cat.category_id }) - if (category) { - context.dispatch('category/single', { key: 'id', value: category.id }, { root: true }).then((category) => { // this sets up category path and current category - setbrcmb(context.rootState.category.current_path) - }).catch(err => { - setbrcmb(context.rootState.category.current_path) - console.error(err) - }) - break - } + if (product.category && product.category.length > 0) { + const categoryIds = product.category.reverse().map((cat => cat.category_id)) + + subloaders.push( + context.dispatch('category/list', {}, { root: true }).then((categories) => { + const catList = [] + + for (let catId of categoryIds) { + let category = categories.items.find((itm) => { return itm['id'] === parseInt(catId) }) + if (category) { + catList.push(category) } + } + + const rootCat = catList.shift() + let catForBreadcrumbs = rootCat + + for (let cat of catList) { + const catPath = cat.path + if (catPath && catPath.includes(rootCat.path) && (catPath.split('/').length > catForBreadcrumbs.path.split('/').length)) { + catForBreadcrumbs = cat + } + } + + context.dispatch('category/single', { key: 'id', value: catForBreadcrumbs.id }, { root: true }).then(() => { // this sets up category path and current category + setbrcmb(context.rootState.category.current_path) }).catch(err => { + setbrcmb(context.rootState.category.current_path) console.error(err) }) - ) - } + }).catch(err => { + console.error(err) + }) + ) } context.state.breadcrumbs.name = product.name - return Promise.all(subloaders) }, doPlatformPricesSync (context, { products }) {