Skip to content

Commit dd89eb8

Browse files
committed
INTEG-707 Simplify application of root category
1 parent fc882c0 commit dd89eb8

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

view/frontend/web/instantsearch.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -446,40 +446,25 @@ define(
446446
* Custom widgets can be added to this object like [attribute]: function(facet, templates)
447447
* Function must return an array [<widget name>: string, <widget options>: object]
448448
**/
449-
var customAttributeFacet = {
449+
const customAttributeFacet = {
450450
categories: function (facet, templates) {
451-
var hierarchical_levels = [];
452-
for (var l = 0; l < 10; l++) {
451+
const hierarchical_levels = [];
452+
for (let l = 0; l < 10; l++) {
453453
hierarchical_levels.push('categories.level' + l.toString());
454454
}
455455

456-
457-
//return array of items starting from root based on category
458-
const findRoot = (items) => {
459-
const root = items.find(element => algoliaConfig.request.path.startsWith(element.value));
460-
461-
if (!root) {
462-
return items;
463-
}
464-
if (!root.data) {
465-
return [];
466-
}
467-
468-
return findRoot(root.data);
469-
470-
};
471-
472-
var hierarchicalMenuParams = {
456+
const hierarchicalMenuParams = {
473457
container : facet.wrapper.appendChild(createISWidgetContainer(facet.attribute)),
474458
attributes : hierarchical_levels,
475459
separator : algoliaConfig.instant.categorySeparator,
476460
templates : templates,
477461
showParentLevel : true,
478-
limit : 999, // arbitrarily high number - as premature truncate of results can prevent preselection for large category lists
462+
limit : algoliaConfig.maxValuesPerFacet,
463+
rootPath : algoliaConfig.request.path,
479464
sortBy : ['name:asc'],
480465
transformItems(items) {
481466
return (algoliaConfig.isCategoryPage)
482-
? findRoot(items).map(
467+
? items.map(
483468
item => {
484469
return {
485470
...item,
@@ -726,4 +711,4 @@ define(
726711
return options;
727712
}
728713
}
729-
);
714+
);

0 commit comments

Comments
 (0)