-
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 layered navigation attributes management
* Add layered navigation attributes management * Add No value filter for boolean * Fix applying boolean filters on GraphQL
- Loading branch information
1 parent
df735e0
commit 58983db
Showing
11 changed files
with
448 additions
and
63 deletions.
There are no files selected for viewing
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
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
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
53 changes: 53 additions & 0 deletions
53
src/module-elasticsuite-catalog/Api/LayeredNavAttributeInterface.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; | ||
|
||
/** | ||
* LayeredNavAttributeInterface class. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Botis <botis@smile.fr> | ||
*/ | ||
interface LayeredNavAttributeInterface | ||
{ | ||
/** | ||
* 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; | ||
} |
100 changes: 100 additions & 0 deletions
100
src/module-elasticsuite-catalog/Model/Attribute/LayeredNavAttributesProvider.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\LayeredNavAttributeInterface; | ||
|
||
/** | ||
* Layered navigation attributes provider. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCatalog | ||
* @author Botis <botis@smile.fr> | ||
*/ | ||
class LayeredNavAttributesProvider | ||
{ | ||
/** | ||
* @var LayeredNavAttributeInterface[] | ||
*/ | ||
protected $attributes = []; | ||
|
||
/** | ||
* LayeredNavAttributesProvider constructor. | ||
* | ||
* @param LayeredNavAttributeInterface[] $attributes Attributes. | ||
*/ | ||
public function __construct($attributes = []) | ||
{ | ||
$this->attributes = $attributes; | ||
} | ||
|
||
/** | ||
* Get Layered navigation attributes list. | ||
* | ||
* @return LayeredNavAttributeInterface[] | ||
*/ | ||
public function getList(): array | ||
{ | ||
$attributes = []; | ||
foreach ($this->attributes as $attribute) { | ||
if (!$attribute->skipAttribute()) { | ||
$attributes[$attribute->getAttributeCode()] = $attribute; | ||
} | ||
} | ||
|
||
return $attributes; | ||
} | ||
|
||
/** | ||
* Get layered navigation attribute. | ||
* | ||
* @param string $attributeCode Attribute code. | ||
* | ||
* @return LayeredNavAttributeInterface|null | ||
*/ | ||
public function getLayeredNavAttribute(string $attributeCode): ?LayeredNavAttributeInterface | ||
{ | ||
return $this->getList()[$attributeCode] ?? null; | ||
} | ||
|
||
/** | ||
* Get layered navigation attribute by filter field. | ||
* | ||
* @param string $filterField Filter field. | ||
* | ||
* @return string|null | ||
*/ | ||
public function getLayeredNavAttributeByFilterField(string $filterField): ?string | ||
{ | ||
foreach ($this->getList() as $attribute) { | ||
if ($attribute->getFilterField() === $filterField) { | ||
return $attribute->getAttributeCode(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Check if it is a layered navigation attribute. | ||
* | ||
* @param string $attributeCode Attribute code. | ||
* | ||
* @return bool | ||
*/ | ||
public function isLayeredNavAttribute(string $attributeCode): bool | ||
{ | ||
return isset($this->getList()[$attributeCode]); | ||
} | ||
} |
Oops, something went wrong.