diff --git a/src/module-elasticsuite-catalog/Api/Layer/Filter/TypeProviderInterface.php b/src/module-elasticsuite-catalog/Api/Layer/Filter/TypeProviderInterface.php new file mode 100644 index 000000000..454b09d21 --- /dev/null +++ b/src/module-elasticsuite-catalog/Api/Layer/Filter/TypeProviderInterface.php @@ -0,0 +1,36 @@ + + * @copyright 2026 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\ElasticsuiteCatalog\Api\Layer\Filter; + +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; + +/** + * Filter type provider interface. + * + * @category Smile + * @package Smile\ElasticsuiteCatalog + * @author Vadym Honcharuk + */ +interface TypeProviderInterface +{ + /** + * Return filter class name. + * + * @param Attribute $attribute The attribute model. + * @param string $originalFilterClassName The original/default filter class name. + * + * @return string + */ + public function getFilterClassName(Attribute $attribute, string $originalFilterClassName): string; +} diff --git a/src/module-elasticsuite-catalog/Model/Layer/FilterList.php b/src/module-elasticsuite-catalog/Model/Layer/FilterList.php index ce1d31bd6..90cb5f72a 100644 --- a/src/module-elasticsuite-catalog/Model/Layer/FilterList.php +++ b/src/module-elasticsuite-catalog/Model/Layer/FilterList.php @@ -14,6 +14,11 @@ namespace Smile\ElasticsuiteCatalog\Model\Layer; +use Magento\Catalog\Model\Config\LayerCategoryConfig; +use Magento\Catalog\Model\Layer\FilterableAttributeListInterface; +use Magento\Framework\ObjectManagerInterface; +use Smile\ElasticsuiteCatalog\Api\Layer\Filter\TypeProviderInterface; + /** * FilterList customization to support decimal filters. * @@ -28,6 +33,37 @@ class FilterList extends \Magento\Catalog\Model\Layer\FilterList */ const BOOLEAN_FILTER = 'boolean'; + /** + * @var TypeProviderInterface[] + */ + private $filterTypeProviders; + + /** + * Constructor. + * + * @param ObjectManagerInterface $objectManager Object manager. + * @param FilterableAttributeListInterface $filterableAttributes Filterable attributes list. + * @param LayerCategoryConfig $layerCategoryConfig Category layer config. + * @param array $filters Core filters array. + * @param array $filterTypeProviders Injected custom type providers. + */ + public function __construct( + ObjectManagerInterface $objectManager, + FilterableAttributeListInterface $filterableAttributes, + LayerCategoryConfig $layerCategoryConfig, + array $filters = [], + array $filterTypeProviders = [] + ) { + parent::__construct( + $objectManager, + $filterableAttributes, + $layerCategoryConfig, + $filters + ); + + $this->filterTypeProviders = $filterTypeProviders; + } + /** * {@inheritDoc} */ @@ -45,6 +81,13 @@ protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\ $filterClassName = $this->filterTypes[self::BOOLEAN_FILTER]; } + // Allow injected providers to override the filter class. + foreach ($this->filterTypeProviders as $provider) { + if ($provider instanceof TypeProviderInterface) { + $filterClassName = $provider->getFilterClassName($attribute, $filterClassName); + } + } + return $filterClassName; } }