Skip to content

Commit 96effa6

Browse files
committed
MAGE-569 Add conditional currentRefinements for subcategory facets
1 parent 7dc7224 commit 96effa6

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

view/frontend/web/instantsearch.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,26 +261,35 @@ requirejs(['algoliaBundle', 'Magento_Catalog/js/price-utils'], function (algolia
261261
templates: {
262262
item: $('#current-refinements-template').html()
263263
},
264-
includedAttributes: attributes.map(function (attribute) {
265-
if (!(algoliaConfig.isCategoryPage && attribute.name.indexOf('categories') > -1)) {
264+
includedAttributes: attributes.map(attribute => {
265+
console.warn("Refinement:", attribute);
266+
if (attribute.name.indexOf('categories') === -1
267+
|| algoliaConfig.instant.isVisualMerchEnabled
268+
|| !algoliaConfig.isCategoryPage)
266269
return attribute.name;
267-
}
268270
}),
269-
transformItems: function (items) {
270-
return items.map(function (item) {
271-
var attribute = attributes.filter(function (_attribute) {
272-
return item.attribute === _attribute.name
273-
})[0];
274-
if (!attribute) return item;
275-
item.label = attribute.label;
276-
item.refinements.forEach(function (refinement) {
277-
if (refinement.type !== 'hierarchical') return refinement;
278-
var levels = refinement.label.split(algoliaConfig.instant.categorySeparator);
279-
var lastLevel = levels[levels.length - 1];
280-
refinement.label = lastLevel;
281-
});
282-
return item;
283-
})
271+
transformItems: items => {
272+
console.log("%cRefinement transform:%o", 'color:green;background:yellow', items);
273+
return items
274+
.filter(item => {
275+
return !algoliaConfig.isCategoryPage
276+
|| item.refinements.filter(refinement => refinement.value !== algoliaConfig.request.path).length; // do not expose the category root
277+
})
278+
.map(item => {
279+
const attribute = attributes.filter(_attribute => {
280+
return item.attribute === _attribute.name
281+
})[0];
282+
if (!attribute) return item;
283+
item.label = attribute.label;
284+
item.refinements.forEach(function (refinement) {
285+
if (refinement.type !== 'hierarchical') return refinement;
286+
287+
const levels = refinement.label.split(algoliaConfig.instant.categorySeparator);
288+
const lastLevel = levels[levels.length - 1];
289+
refinement.label = lastLevel;
290+
});
291+
return item;
292+
})
284293
}
285294
},
286295

0 commit comments

Comments
 (0)