Skip to content

Commit 17ebfc7

Browse files
committed
Allow enable discount percentage filter
1 parent ee3b942 commit 17ebfc7

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* DISCLAIMER
4+
*
5+
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer versions in the future.
6+
*
7+
* @category Smile
8+
* @package Smile\ElasticsuiteCatalog
9+
* @author Vadym Honcharuk <vahonc@smile.fr>
10+
* @copyright 2026 Smile
11+
* @license Open Software License ("OSL") v. 3.0
12+
*/
13+
14+
namespace Smile\ElasticsuiteCatalog\Api\Layer\Filter;
15+
16+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
17+
18+
/**
19+
* Filter type provider interface.
20+
*
21+
* @category Smile
22+
* @package Smile\ElasticsuiteCatalog
23+
* @author Vadym Honcharuk <vahonc@smile.fr>
24+
*/
25+
interface TypeProviderInterface
26+
{
27+
/**
28+
* Return filter class name.
29+
*
30+
* @param Attribute $attribute The attribute model.
31+
* @param string $originalFilterClassName The original/default filter class name.
32+
*
33+
* @return string
34+
*/
35+
public function getFilterClassName(Attribute $attribute, string $originalFilterClassName): string;
36+
}

src/module-elasticsuite-catalog/Model/Layer/FilterList.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
namespace Smile\ElasticsuiteCatalog\Model\Layer;
1616

17+
use Magento\Catalog\Model\Config\LayerCategoryConfig;
18+
use Magento\Catalog\Model\Layer\FilterableAttributeListInterface;
19+
use Magento\Framework\ObjectManagerInterface;
20+
use Smile\ElasticsuiteCatalog\Api\Layer\Filter\TypeProviderInterface;
21+
1722
/**
1823
* FilterList customization to support decimal filters.
1924
*
@@ -28,6 +33,37 @@ class FilterList extends \Magento\Catalog\Model\Layer\FilterList
2833
*/
2934
const BOOLEAN_FILTER = 'boolean';
3035

36+
/**
37+
* @var TypeProviderInterface[]
38+
*/
39+
private $filterTypeProviders;
40+
41+
/**
42+
* Constructor.
43+
*
44+
* @param ObjectManagerInterface $objectManager Object manager.
45+
* @param FilterableAttributeListInterface $filterableAttributes Filterable attributes list.
46+
* @param LayerCategoryConfig $layerCategoryConfig Category layer config.
47+
* @param array $filters Core filters array.
48+
* @param array $filterTypeProviders Injected custom type providers.
49+
*/
50+
public function __construct(
51+
ObjectManagerInterface $objectManager,
52+
FilterableAttributeListInterface $filterableAttributes,
53+
LayerCategoryConfig $layerCategoryConfig,
54+
array $filters = [],
55+
array $filterTypeProviders = []
56+
) {
57+
parent::__construct(
58+
$objectManager,
59+
$filterableAttributes,
60+
$layerCategoryConfig,
61+
$filters
62+
);
63+
64+
$this->filterTypeProviders = $filterTypeProviders;
65+
}
66+
3167
/**
3268
* {@inheritDoc}
3369
*/
@@ -45,6 +81,13 @@ protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\
4581
$filterClassName = $this->filterTypes[self::BOOLEAN_FILTER];
4682
}
4783

84+
// Allow injected providers to override the filter class.
85+
foreach ($this->filterTypeProviders as $provider) {
86+
if ($provider instanceof TypeProviderInterface) {
87+
$filterClassName = $provider->getFilterClassName($attribute, $filterClassName);
88+
}
89+
}
90+
4891
return $filterClassName;
4992
}
5093
}

0 commit comments

Comments
 (0)