Skip to content

Commit af56d89

Browse files
committed
[RuleEngine] Attribute Locator interface, minor code refactoring
1 parent 73617ac commit af56d89

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

src/module-elasticsuite-catalog-optimizer/Model/Rule/Attribute/OptimizerLocationProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Smile\ElasticsuiteCatalogOptimizer\Model\Rule\Attribute;
1616

1717
use Magento\Framework\App\ResourceConnection;
18+
use Smile\ElasticsuiteCatalogOptimizer\Api\Data\OptimizerInterface;
1819
use Smile\ElasticsuiteCatalogRule\Api\Rule\Attribute\LocationProviderInterface;
1920

2021
/**
@@ -36,11 +37,6 @@
3637
*/
3738
class OptimizerLocationProvider implements LocationProviderInterface
3839
{
39-
/**
40-
* Optimizer table name.
41-
*/
42-
private const TABLE_NAME = 'smile_elasticsuite_optimizer';
43-
4440
/**
4541
* @var ResourceConnection
4642
*/
@@ -72,7 +68,7 @@ public function isPresent(string $attribute): bool
7268
}
7369

7470
$connection = $this->resource->getConnection();
75-
$tableName = $this->resource->getTableName(self::TABLE_NAME);
71+
$tableName = $this->resource->getTableName(OptimizerInterface::TABLE_NAME);
7672

7773
/**
7874
* Build LIKE pattern:

src/module-elasticsuite-virtual-category/Model/Rule/Attribute/VirtualCategoryLocationProvider.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\App\ResourceConnection;
1919
use Magento\Framework\Exception\NoSuchEntityException;
2020
use Smile\ElasticsuiteCatalogRule\Api\Rule\Attribute\LocationProviderInterface;
21+
use Magento\Catalog\Api\Data\CategoryAttributeInterface;
2122

2223
/**
2324
* Virtual Category Attribute Location Provider.
@@ -41,16 +42,6 @@
4142
*/
4243
class VirtualCategoryLocationProvider implements LocationProviderInterface
4344
{
44-
/**
45-
* Attribute code storing virtual category rules.
46-
*/
47-
private const ATTRIBUTE_CODE = 'virtual_rule';
48-
49-
/**
50-
* Entity type code for categories.
51-
*/
52-
private const ENTITY_TYPE = 'catalog_category';
53-
5445
/**
5546
* @var ResourceConnection
5647
*/
@@ -61,19 +52,27 @@ class VirtualCategoryLocationProvider implements LocationProviderInterface
6152
*/
6253
private AttributeRepositoryInterface $attributeRepository;
6354

55+
/**
56+
* @var string
57+
*/
58+
private string $attributeCode;
59+
6460
/**
6561
* Constructor.
6662
*
6763
* @param ResourceConnection $resource Database resource connection.
6864
* @param AttributeRepositoryInterface $attributeRepository Repository used to retrieve EAV attribute metadata
6965
* (attribute ID and backend table for virtual_rule).
66+
* @param string $attributeCode Attribute code used to store virtual category rules.
7067
*/
7168
public function __construct(
7269
ResourceConnection $resource,
73-
AttributeRepositoryInterface $attributeRepository
70+
AttributeRepositoryInterface $attributeRepository,
71+
string $attributeCode = 'virtual_rule'
7472
) {
7573
$this->resource = $resource;
7674
$this->attributeRepository = $attributeRepository;
75+
$this->attributeCode = $attributeCode;
7776
}
7877

7978
/**
@@ -91,8 +90,8 @@ public function isPresent(string $attribute): bool
9190
try {
9291
// Load the virtual_rule attribute metadata.
9392
$eavAttribute = $this->attributeRepository->get(
94-
self::ENTITY_TYPE,
95-
self::ATTRIBUTE_CODE
93+
CategoryAttributeInterface::ENTITY_TYPE_CODE,
94+
$this->attributeCode
9695
);
9796
} catch (NoSuchEntityException $e) {
9897
// Attribute not found => cannot be used anywhere.

0 commit comments

Comments
 (0)