1818use Magento \Framework \App \ResourceConnection ;
1919use Magento \Framework \Exception \NoSuchEntityException ;
2020use Smile \ElasticsuiteCatalogRule \Api \Rule \Attribute \LocationProviderInterface ;
21+ use Magento \Catalog \Api \Data \CategoryAttributeInterface ;
2122
2223/**
2324 * Virtual Category Attribute Location Provider.
4142 */
4243class 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