SyliusElasticsearchPlugin icon indicating copy to clipboard operation
SyliusElasticsearchPlugin copied to clipboard

Issue with Non-Translatable Attribute Facets

Open celiamaurewide opened this issue 1 year ago • 0 comments

Hello! I am facing an issue when defining a facet for a non-translatable attribute. In Elasticsearch, non-translatable attributes are indexed with properties formatted as attribute_attributecode_ (without a locale suffix). However, the BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet class requires a LocaleContextInterface and always queries attribute_attributecode_localecode, even when the attribute is non-translatable. As a result, no results are returned for such facets.

For example, my configuration looks like this:

bitbag_sylius_elasticsearch_plugin.facet.attribute.filter_cooking:
    class: BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet
    arguments:
        - '@bitbag_sylius_elasticsearch_plugin.property_name_resolver.attribute'
        - '@=service("sylius.repository.product_attribute").findOneBy({"code": "filter_cooking"})'
        - '@sylius.context.locale' # here is the locale that is required by the class

BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet
private function getFieldName(): string
{
    return sprintf(
        '%s_%s.keyword',
        $this->attributeNameResolver->resolvePropertyName((string) $this->getProductAttribute()->getCode()),
        $this->localeContext->getLocaleCode() // This is where the locale causes a problem, as it is not nullable
    );
}

Is there an existing solution or workaround for this issue?

celiamaurewide avatar Nov 11 '24 14:11 celiamaurewide