Skip to content
Merged
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
2 changes: 1 addition & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
53 changes: 30 additions & 23 deletions core/store/modules/product/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,43 @@ const actions: ActionTree<ProductState, RootState> = {
}
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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path field was not required before and if somebody is using for example M1 connector can have problem with this field being empty.

Can we easily add a fallback to the previous behavior - modified just by the way you’re selecting the root category?

So when the path is not set let’s generate breadcrumbs the previous way with parents

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 }) {
Expand Down