Skip to content

Commit 04ca764

Browse files
committed
MAGE-569 Anchor category faceting based category context (only show subcategories)
1 parent 622fa6a commit 04ca764

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

view/adminhtml/templates/landingpage/search-configuration.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ $isConfig = [
485485
container: facet.wrapper.appendChild(createISWidgetContainer(facet.attribute)),
486486
attributes: hierarchical_levels,
487487
separator: config.categorySeparator,
488-
alwaysGetRootLevel: true,
489488
limit: config.maxValuesPerFacet,
490489
templates: templates,
491490
sortBy: ['name:asc'],

view/frontend/web/instantsearch.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ requirejs(['algoliaBundle', 'Magento_Catalog/js/price-utils'], function (algolia
102102
searchParameters['facetsRefinements']['categories.level' + algoliaConfig.request.level] = [algoliaConfig.request.path];
103103
}
104104
}
105-
105+
106106
if (algoliaConfig.instant.isVisualMerchEnabled && algoliaConfig.isCategoryPage ) {
107107
searchParameters.filters = `${algoliaConfig.instant.categoryPageIdAttribute}:'${algoliaConfig.request.path}'`;
108108
}
@@ -431,29 +431,33 @@ requirejs(['algoliaBundle', 'Magento_Catalog/js/price-utils'], function (algolia
431431
hierarchical_levels.push('categories.level' + l.toString());
432432
}
433433

434+
435+
//return array of items starting from root based on category
436+
const findRoot = (items) => {
437+
const root = items.find(element => algoliaConfig.request.path.startsWith(element.value));
438+
439+
if (!root) {
440+
return items;
441+
}
442+
if (!root.data) {
443+
return [];
444+
}
445+
446+
return findRoot(root.data);
447+
448+
};
434449
var hierarchicalMenuParams = {
435450
container: facet.wrapper.appendChild(createISWidgetContainer(facet.attribute)),
436451
attributes: hierarchical_levels,
437452
separator: algoliaConfig.instant.categorySeparator,
438453
templates: templates,
439-
alwaysGetRootLevel: false,
440-
showParentLevel:false,
454+
showParentLevel: true,
441455
limit: algoliaConfig.maxValuesPerFacet,
442456
sortBy: ['name:asc'],
443457
transformItems(items) {
444-
if(algoliaConfig.isCategoryPage) {
445-
var filteredData = [];
446-
items.forEach(element => {
447-
if (element.label == algoliaConfig.request.parentCategory) {
448-
filteredData.push(element);
449-
};
450-
});
451-
items = filteredData;
452-
}
453-
return items.map(item => ({
454-
...item,
455-
label: item.label,
456-
}));
458+
return (algoliaConfig.isCategoryPage)
459+
? findRoot(items)
460+
: items;
457461
},
458462
};
459463

0 commit comments

Comments
 (0)