Smile-SA / elasticsuite

Smile ElasticSuite - Magento 2 merchandising and search engine built on ElasticSearch
https://elasticsuite.io
Open Software License 3.0
761 stars 340 forks source link

Faceted data has not attribute_code but option_text_attribute_code instead. How to get attribute_code faceted data? #3307

Closed zakdma closed 2 months ago

zakdma commented 3 months ago

Hi! I have a problem with code that use faceted data to build some output. Elasticsuite replaced \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection with \Smile\ElasticsuiteCatalog\Model\ResourceModel\Product\Fulltext\Collection This collection has method getFacetedData that behaves differently than Magento core one. Core return data for attribute_code and attribute option ID so I can easily identify counts linked to options But your implementation returns option_text_attribute_code. And its has not option ID rather option text. So I cannot easily identify option by it. Is there any possibility of getting faceted data for attribute_code?

Thank you.

rbayet commented 3 months ago

Hello @zakdma,

Indeed, by default, for select and multiselect, the facets/aggregations are computed on the field containing the untouched labels of options. But it does contain the counts associated to each option, which should be pretty much the same thing considering than Magento does not allow you to have duplicate labels.

Out of curiosity, why do you need to build the facets/aggregations on the optionId instead exactly ? Is it for tracking purposes ?

Anyway, one way would be to create a plugin on \Smile\ElasticsuiteCatalog\Helper\ProductAttribute::getFilterField and on a per-attribute or per-attribute type basis, decide to change the field used but you'll probably safer to override both

Regards,

zakdma commented 2 months ago

Hi! Yeah its a workarond but it would be great to have such ability by configuration. I mean make a configuration to decide use option_text_attribute_code or attribute_code. Now its hardcoded. Anyway, thank you for response.

rbayet commented 2 months ago

They will be part of our module that are somehow "hardcoded" to provide its features, but it does provide extension/override points. It felt logical at design time to make facets on the "untouched" label of select/multiselect because it does avoid having to reload the options.

Anyway, you're welcome @zakdma