When implementing a Multi-Language Search in a Single Store the records are structured as objects:
This becomes an issue when we want to display these records as facet attributes in our front end. These attributes don't seem to appear in the front end, even though they are configured as filterable.
To change this, we need to add a front end custom event in the JS code of our theme that renders a widget for this filter, that is a normal refinement list widget. For example, we would need to target the right key-value pair (“en”: “Shirt”) to display it on our front-end, so instead of having a description as a facet attribute, we need description.en.
We can follow a similar approach here https://www.algolia.com/doc/integration/magento-2/customize/custom-front-end-events/?client=php#instant-search-page-events:
algolia.registerHook('beforeWidgetInitialization', function(allWidgetConfiguration) {
const wrapper = document.getElementById('instant-search-facets-container');
const widgetConfig = {
container: wrapper.appendChild(createISWidgetContainer('in_stock')),
attribute: 'in_stock',
on: 1,
templates: {
label: 'In Stock'
}
};
if (typeof allWidgetConfiguration['toggleRefinement'] === 'undefined') {
allWidgetConfiguration['toggleRefinement'] = [widgetConfig];
} else {
allWidgetConfiguration['toggleRefinement'].push(widgetConfig);
}
return allWidgetConfiguration;
});