Skip to content

Commit 2b2c1d7

Browse files
authored
Merge pull request #1426 from algolia/bugfix/MAGE-773
Bugfix/mage 773 improved category anchor
2 parents e33b2f9 + 3ade12f commit 2b2c1d7

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

view/frontend/web/instantsearch.js

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -448,40 +448,25 @@ define(
448448
* Custom widgets can be added to this object like [attribute]: function(facet, templates)
449449
* Function must return an array [<widget name>: string, <widget options>: object]
450450
**/
451-
var customAttributeFacet = {
451+
const customAttributeFacet = {
452452
categories: function (facet, templates) {
453-
var hierarchical_levels = [];
454-
for (var l = 0; l < 10; l++) {
453+
const hierarchical_levels = [];
454+
for (let l = 0; l < 10; l++) {
455455
hierarchical_levels.push('categories.level' + l.toString());
456456
}
457457

458-
459-
//return array of items starting from root based on category
460-
const findRoot = (items) => {
461-
const root = items.find(element => algoliaConfig.request.path.startsWith(element.value));
462-
463-
if (!root) {
464-
return items;
465-
}
466-
if (!root.data) {
467-
return [];
468-
}
469-
470-
return findRoot(root.data);
471-
472-
};
473-
474-
var hierarchicalMenuParams = {
458+
const hierarchicalMenuParams = {
475459
container : facet.wrapper.appendChild(createISWidgetContainer(facet.attribute)),
476460
attributes : hierarchical_levels,
477461
separator : algoliaConfig.instant.categorySeparator,
478462
templates : templates,
479463
showParentLevel : true,
480464
limit : algoliaConfig.maxValuesPerFacet,
465+
rootPath : algoliaConfig.request.path,
481466
sortBy : ['name:asc'],
482467
transformItems(items) {
483468
return (algoliaConfig.isCategoryPage)
484-
? findRoot(items).map(
469+
? items.map(
485470
item => {
486471
return {
487472
...item,

view/frontend/web/internals/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ define(['jquery', 'algoliaBundle'], function ($, algoliaBundle) {
405405
if (algoliaConfig.isLandingPage &&
406406
typeof uiStateProductIndex['hierarchicalMenu']['categories.level0'] === 'undefined' &&
407407
'categories.level0' in landingPageConfig) {
408-
uiStateProductIndex['hierarchicalMenu']['categories.level0'] = landingPageConfig['categories.level0'].split(' /// ');
408+
uiStateProductIndex['hierarchicalMenu']['categories.level0'] = landingPageConfig['categories.level0'].split(algoliaConfig.instant.categorySeparator);
409409
}
410410
}
411411
if (currentFacet.attribute == 'categories' && algoliaConfig.isCategoryPage) {

0 commit comments

Comments
 (0)