Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Vadym Honcharuk <vahonc@smile.fr>
* @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 <vahonc@smile.fr>
*/
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;
}
43 changes: 43 additions & 0 deletions src/module-elasticsuite-catalog/Model/Layer/FilterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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}
*/
Expand All @@ -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;
}
}
Loading