Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
botisSmile committed Oct 12, 2021
1 parent 89988cc commit 746edb8
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface;
use Smile\ElasticsuiteCore\Api\Index\MappingInterface;
use Smile\ElasticsuiteCore\Helper\Mapping as MappingHelper;
use Smile\ElasticsuiteCatalog\Model\Attribute\SpecialAttributesProvider as CatalogSpecialAttributesProvider;
use Smile\ElasticsuiteCatalog\Model\Attribute\LayeredNavAttributesProvider;

/**
* List of attributes used in query building.
Expand Down Expand Up @@ -77,40 +77,40 @@ class AttributeList
private $requestFieldMapper;

/**
* @var CatalogSpecialAttributesProvider
* @var LayeredNavAttributesProvider
*/
private $catalogSpecialAttributesProvider;
private $layeredNavAttributesProvider;

/**
* Constructor.
*
* @param AttributeCollectionFactory $attributeCollectionFactory Product attribute collection factory.
* @param StoreManagerInterface $storeManager Store manager.
* @param IndexOperationInterface $indexManager Search engine index manager.
* @param MappingHelper $mappingHelper Mapping helper.
* @param RequestFieldMapper $requestFieldMapper Search request field mapper.
* @param CatalogSpecialAttributesProvider $catalogSpecialAttributesProvider Catalog special attributes provider
* @param string $indexName Search engine index name.
* @param string $typeName Search engine type name.
* @param AttributeCollectionFactory $attributeCollectionFactory Product attribute collection factory.
* @param StoreManagerInterface $storeManager Store manager.
* @param IndexOperationInterface $indexManager Search engine index manager.
* @param MappingHelper $mappingHelper Mapping helper.
* @param RequestFieldMapper $requestFieldMapper Search request field mapper.
* @param LayeredNavAttributesProvider $layeredNavAttributesProvider Layered navigation attributes provider.
* @param string $indexName Search engine index name.
* @param string $typeName Search engine type name.
*/
public function __construct(
AttributeCollectionFactory $attributeCollectionFactory,
StoreManagerInterface $storeManager,
IndexOperationInterface $indexManager,
MappingHelper $mappingHelper,
RequestFieldMapper $requestFieldMapper,
CatalogSpecialAttributesProvider $catalogSpecialAttributesProvider,
LayeredNavAttributesProvider $layeredNavAttributesProvider,
$indexName = 'catalog_product',
$typeName = 'product'
) {
$this->attributeCollectionFactory = $attributeCollectionFactory;
$this->storeManager = $storeManager;
$this->indexManager = $indexManager;
$this->mappingHelper = $mappingHelper;
$this->requestFieldMapper = $requestFieldMapper;
$this->catalogSpecialAttributesProvider = $catalogSpecialAttributesProvider;
$this->indexName = $indexName;
$this->typeName = $typeName;
$this->attributeCollectionFactory = $attributeCollectionFactory;
$this->storeManager = $storeManager;
$this->indexManager = $indexManager;
$this->mappingHelper = $mappingHelper;
$this->requestFieldMapper = $requestFieldMapper;
$this->layeredNavAttributesProvider = $layeredNavAttributesProvider;
$this->indexName = $indexName;
$this->typeName = $typeName;
}

/**
Expand Down Expand Up @@ -139,10 +139,10 @@ public function getAttributeCollection()
$this->attributeCollection->addFieldToFilter('attribute_code', $fieldNames)
->addFieldToFilter('backend_type', ['neq' => 'datetime']);

if (!empty($this->catalogSpecialAttributesProvider->getList())) {
if (!empty($this->layeredNavAttributesProvider->getList())) {
$this->attributeCollection->addFieldToFilter(
'attribute_code',
['nin' => array_keys($this->catalogSpecialAttributesProvider->getList())]
['nin' => array_keys($this->layeredNavAttributesProvider->getList())]
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
namespace Smile\ElasticsuiteCatalog\Api;

/**
* SpecialAttributeInterface class.
* LayeredNavAttributeInterface class.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Botis <botis@smile.fr>
*/
interface SpecialAttributeInterface
interface LayeredNavAttributeInterface
{
/**
* Get attribute code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\LayerBuilderInterface;
use Magento\Framework\Api\Search\AggregationInterface;
use Magento\Framework\Api\Search\BucketInterface;
use Smile\ElasticsuiteCatalog\Model\Attribute\SpecialAttributesProvider;
use Smile\ElasticsuiteCatalog\Model\Attribute\LayeredNavAttributesProvider;
use Smile\ElasticsuiteCore\Helper\Mapping;

/**
Expand Down Expand Up @@ -54,9 +54,9 @@ class Attribute // Not implementing the LayerBuilderInterface because it did not
private $attributeRepository;

/**
* @var SpecialAttributesProvider
* @var LayeredNavAttributesProvider
*/
protected $specialAttributesProvider;
protected $layeredNavAttributesProvider;

/**
* @var array
Expand All @@ -67,22 +67,22 @@ class Attribute // Not implementing the LayerBuilderInterface because it did not
];

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager Object Manager.
* @param AttributeRepository $attributeRepository Attribute Repository.
* @param SpecialAttributesProvider $specialAttributesProvider Special Attributes Provider.
* @param array $bucketNameFilter Bucket Filter.
* @param \Magento\Framework\ObjectManagerInterface $objectManager Object Manager.
* @param AttributeRepository $attributeRepository Attribute Repository.
* @param LayeredNavAttributesProvider $layeredNavAttributesProvider Layered navigation attributes provider.
* @param array $bucketNameFilter Bucket Filter.
*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
AttributeRepository $attributeRepository,
SpecialAttributesProvider $specialAttributesProvider,
LayeredNavAttributesProvider $layeredNavAttributesProvider,
$bucketNameFilter = []
) {
// Using Object Manager for BC with Magento <2.3.4.
$this->layerFormatter = $objectManager->get(LayerFormatter::class);
$this->bucketNameFilter = \array_merge($this->bucketNameFilter, $bucketNameFilter);
$this->attributeRepository = $attributeRepository;
$this->specialAttributesProvider = $specialAttributesProvider;
$this->layeredNavAttributesProvider = $layeredNavAttributesProvider;
}

/**
Expand All @@ -101,7 +101,7 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
if (substr($bucketName, 0, strlen($prefix)) === $prefix) {
$attributeCode = substr($bucketName, strlen($prefix));
}
$attributeCode = $this->specialAttributesProvider->getSpecialAttributeByFilterField($bucketName) ?? $attributeCode;
$attributeCode = $this->layeredNavAttributesProvider->getLayeredNavAttributeByFilterField($bucketName) ?? $attributeCode;

$label = $attributeCode;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@
*/
namespace Smile\ElasticsuiteCatalog\Model\Attribute;

use Smile\ElasticsuiteCatalog\Api\SpecialAttributeInterface;
use Smile\ElasticsuiteCatalog\Api\LayeredNavAttributeInterface;

/**
* Special Attributes Provider.
* Layered navigation attributes provider.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Botis <botis@smile.fr>
*/
class SpecialAttributesProvider
class LayeredNavAttributesProvider
{
/**
* @var SpecialAttributeInterface[]
* @var LayeredNavAttributeInterface[]
*/
protected $attributes = [];

/**
* SpecialAttributesProvider constructor.
* LayeredNavAttributesProvider constructor.
*
* @param SpecialAttributeInterface[] $attributes Attributes.
* @param LayeredNavAttributeInterface[] $attributes Attributes.
*/
public function __construct($attributes = [])
{
$this->attributes = $attributes;
}

/**
* Get special attributes list.
* Get Layered navigation attributes list.
*
* @return SpecialAttributeInterface[]
* @return LayeredNavAttributeInterface[]
*/
public function getList(): array
{
Expand All @@ -57,25 +57,25 @@ public function getList(): array
}

/**
* Get special attribute.
* Get layered navigation attribute.
*
* @param string $attributeCode Attribute code.
*
* @return SpecialAttributeInterface|null
* @return LayeredNavAttributeInterface|null
*/
public function getSpecialAttribute(string $attributeCode): ?SpecialAttributeInterface
public function getLayeredNavAttribute(string $attributeCode): ?LayeredNavAttributeInterface
{
return $this->getList()[$attributeCode] ?? null;
}

/**
* Get special attribute.
* Get layered navigation attribute by filter field.
*
* @param string $filterField Filter field.
*
* @return string|null
*/
public function getSpecialAttributeByFilterField(string $filterField): ?string
public function getLayeredNavAttributeByFilterField(string $filterField): ?string
{
foreach ($this->getList() as $attribute) {
if ($attribute->getFilterField() === $filterField) {
Expand All @@ -87,13 +87,13 @@ public function getSpecialAttributeByFilterField(string $filterField): ?string
}

/**
* Check if attribute is special.
* Check if it is a layered navigation attribute.
*
* @param string $attributeCode Attribute code.
*
* @return bool
*/
public function isSpecialAttribute(string $attributeCode): bool
public function isLayeredNavAttribute(string $attributeCode): bool
{
return isset($this->getList()[$attributeCode]);
}
Expand Down
36 changes: 18 additions & 18 deletions src/module-elasticsuite-catalog/Model/Layer/Filter/Boolean.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
use Magento\Framework\Escaper;
use Magento\Framework\Filter\StripTags;
use Magento\Store\Model\StoreManagerInterface;
use Smile\ElasticsuiteCatalog\Api\SpecialAttributeInterface;
use Smile\ElasticsuiteCatalog\Api\LayeredNavAttributeInterface;
use Smile\ElasticsuiteCatalog\Helper\ProductAttribute;
use Smile\ElasticsuiteCatalog\Model\Attribute\SpecialAttributesProvider;
use Smile\ElasticsuiteCatalog\Model\Attribute\LayeredNavAttributesProvider;

/**
* Product boolean filter implementation.
Expand All @@ -33,22 +33,22 @@
class Boolean extends Attribute
{
/**
* @var SpecialAttributesProvider
* @var LayeredNavAttributesProvider
*/
protected $specialAttributesProvider;
protected $layeredNavAttributesProvider;

/**
* Boolean Constructor.
*
* @param ItemFactory $filterItemFactory Factory for item of the facets.
* @param StoreManagerInterface $storeManager Store manager.
* @param Layer $layer Catalog product layer.
* @param DataBuilder $itemDataBuilder Item data builder.
* @param StripTags $tagFilter String HTML tags filter.
* @param Escaper $escaper Html Escaper.
* @param ProductAttribute $mappingHelper Mapping helper.
* @param SpecialAttributesProvider $specialAttributesProvider Special Attributes Provider.
* @param array $data Custom data.
* @param ItemFactory $filterItemFactory Factory for item of the facets.
* @param StoreManagerInterface $storeManager Store manager.
* @param Layer $layer Catalog product layer.
* @param DataBuilder $itemDataBuilder Item data builder.
* @param StripTags $tagFilter String HTML tags filter.
* @param Escaper $escaper Html Escaper.
* @param ProductAttribute $mappingHelper Mapping helper.
* @param LayeredNavAttributesProvider $layeredNavAttributesProvider Layered navigation attributes Provider.
* @param array $data Custom data.
*/
public function __construct(
ItemFactory $filterItemFactory,
Expand All @@ -58,7 +58,7 @@ public function __construct(
StripTags $tagFilter,
Escaper $escaper,
ProductAttribute $mappingHelper,
SpecialAttributesProvider $specialAttributesProvider,
LayeredNavAttributesProvider $layeredNavAttributesProvider,
array $data = []
) {
parent::__construct(
Expand All @@ -72,7 +72,7 @@ public function __construct(
$data
);

$this->specialAttributesProvider = $specialAttributesProvider;
$this->layeredNavAttributesProvider = $layeredNavAttributesProvider;
}

/**
Expand Down Expand Up @@ -126,9 +126,9 @@ protected function getFilterField()
{
$field = $this->getAttributeModel()->getAttributeCode();

$specialAttribute = $this->specialAttributesProvider->getSpecialAttribute($field);
if ($specialAttribute instanceof SpecialAttributeInterface) {
$field = $specialAttribute->getFilterField();
$layeredNavAttribute = $this->layeredNavAttributesProvider->getLayeredNavAttribute($field);
if ($layeredNavAttribute instanceof LayeredNavAttributeInterface) {
$field = $layeredNavAttribute->getFilterField();
}

return $field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@
namespace Smile\ElasticsuiteCAtalog\Plugin\Search\Request\Product\Attribute\Aggregation;

use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Smile\ElasticsuiteCatalog\Api\SpecialAttributeInterface;
use Smile\ElasticsuiteCatalog\Api\LayeredNavAttributeInterface;
use Smile\ElasticsuiteCatalog\Search\Request\Product\Attribute\AggregationInterface;
use Smile\ElasticsuiteCatalog\Model\Attribute\SpecialAttributesProvider;
use Smile\ElasticsuiteCatalog\Model\Attribute\LayeredNavAttributesProvider;

/**
* Class SpecialAttribute.
* Class LayeredNavAttribute.
*
* @category Smile
* @package Smile\ElasticsuiteCatalog
* @author Botis <botis@smile.fr>
*/
class SpecialAttribute
class LayeredNavAttribute
{
/**
* @var SpecialAttributesProvider
* @var LayeredNavAttributesProvider
*/
private $specialAttributesProvider;
private $layeredNavAttributesProvider;

/**
* SpecialAttribute Constructor.
* LayeredNavAttribute Constructor.
*
* @param SpecialAttributesProvider $specialAttributesProvider Special Attributes Provider.
* @param LayeredNavAttributesProvider $layeredNavAttributesProvider Layered navigation Attributes Provider.
*/
public function __construct(
SpecialAttributesProvider $specialAttributesProvider
LayeredNavAttributesProvider $layeredNavAttributesProvider
) {
$this->specialAttributesProvider = $specialAttributesProvider;
$this->layeredNavAttributesProvider = $layeredNavAttributesProvider;
}

/**
* Replace filter field value for special attributes.
* Replace filter field value for layered navigation attributes.
*
* @param AggregationInterface $subject Plugin subject.
* @param array $result Result.
Expand All @@ -55,10 +55,12 @@ public function __construct(
*/
public function afterGetAggregationData(AggregationInterface $subject, array $result, Attribute $attribute): array
{
$specialAttribute = $this->specialAttributesProvider->getSpecialAttribute($attribute->getAttributeCode());
if ($specialAttribute instanceof SpecialAttributeInterface) {
$result['name'] = $specialAttribute->getFilterField();
$result = array_merge($result, $specialAttribute->getAdditionalAggregationData());
$layeredNavAttribute = $this->layeredNavAttributesProvider->getLayeredNavAttribute(
$attribute->getAttributeCode()
);
if ($layeredNavAttribute instanceof LayeredNavAttributeInterface) {
$result['name'] = $layeredNavAttribute->getFilterField();
$result = array_merge($result, $layeredNavAttribute->getAdditionalAggregationData());
}

return $result;
Expand Down
Loading

0 comments on commit 746edb8

Please sign in to comment.