-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#ESP-252 Add special attributes management
* Add special attributes management * Add No value filter for boolean * Fix applying boolean filters on GraphQL
- Loading branch information
1 parent
b0ed615
commit c644177
Showing
9 changed files
with
412 additions
and
45 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/module-elasticsuite-catalog/Api/SpecialAttributeInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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 Botis <botis@smile.fr> | ||
* @copyright 2021 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteCatalog\Api; | ||
|
||
/** | ||
* SpecialAttributeInterface class. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Botis <botis@smile.fr> | ||
*/ | ||
interface SpecialAttributeInterface | ||
{ | ||
/** | ||
* Get attribute code. | ||
* | ||
* @return string | ||
*/ | ||
public function getAttributeCode(): string; | ||
|
||
/** | ||
* Get ES filter field. | ||
* | ||
* @return string | ||
*/ | ||
public function getFilterField(): string; | ||
|
||
/** | ||
* Get additional aggregation data. | ||
* | ||
* @return array | ||
*/ | ||
public function getAdditionalAggregationData(): array; | ||
|
||
/** | ||
* Skip attribute. | ||
* | ||
* @return bool | ||
*/ | ||
public function skipAttribute(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/module-elasticsuite-catalog/Model/Attribute/SpecialAttributesProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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 Botis <botis@smile.fr> | ||
* @copyright 2021 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
namespace Smile\ElasticsuiteCatalog\Model\Attribute; | ||
|
||
use Smile\ElasticsuiteCatalog\Api\SpecialAttributeInterface; | ||
|
||
/** | ||
* Special Attributes Provider. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Botis <botis@smile.fr> | ||
*/ | ||
class SpecialAttributesProvider | ||
{ | ||
/** | ||
* @var SpecialAttributeInterface[] | ||
*/ | ||
protected $attributes = []; | ||
|
||
/** | ||
* SpecialAttributesProvider constructor. | ||
* | ||
* @param SpecialAttributeInterface[] $attributes Attributes. | ||
*/ | ||
public function __construct($attributes = []) | ||
{ | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* Get special attributes list. | ||
* | ||
* @return SpecialAttributeInterface[] | ||
*/ | ||
public function getList(): array | ||
{ | ||
$attributes = []; | ||
foreach ($this->attributes as $attribute) { | ||
if (!$attribute->skipAttribute()) { | ||
$attributes[$attribute->getAttributeCode()] = $attribute; | ||
} | ||
} | ||
|
||
return $attributes; | ||
} | ||
|
||
/** | ||
* Get special attribute. | ||
* | ||
* @param string $attributeCode Attribute code. | ||
* | ||
* @return SpecialAttributeInterface|null | ||
*/ | ||
public function getSpecialAttribute(string $attributeCode): ?SpecialAttributeInterface | ||
{ | ||
return $this->getList()[$attributeCode] ?? null; | ||
} | ||
|
||
/** | ||
* Get special attribute. | ||
* | ||
* @param string $filterField Filter field. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getSpecialAttributeByFilterField(string $filterField): ?string | ||
{ | ||
foreach ($this->getList() as $attribute) { | ||
if ($attribute->getFilterField() === $filterField) { | ||
return $attribute->getAttributeCode(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Check if attribute is special. | ||
* | ||
* @param string $attributeCode Attribute code. | ||
* | ||
* @return bool | ||
*/ | ||
public function isSpecialAttribute(string $attributeCode): bool | ||
{ | ||
return isset($this->getList()[$attributeCode]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.