Huge size of excluded options/attributes
Hello,
I just meet this problems. Related to my previous issue, I've too much attributes and options. So, I put all of them in the excluded parameters. But when I'm going to the index shop, some times, I can see some options / attributes not excluded even if they're in the excluded list.
Example :
-
I've two taxons : T1, T2
-
I've one option : O1
-
And one attribute : A1
-
The option and the attribute are applied on all products.
-
On T1, I will see no filter on the left.
-
On T2, I will see the O1 and the A1 filters.
I don't know if it's well explained, but if u need further information, ping me :)
Could you please provide a quick fix @damonsson ? Thanks !
In a project where I am working on, we have a similar issue; this seems to be caused by the ProductAttributesFinder that has a hardcoded limit of 20 attributes and is called before the exclusion takes place.
For us, the solution was to override the ProductAttributesFinder class with our own where we have increased the number of attributes to return:
The class:
<?php
declare(strict_types=1);
namespace App\Service\Search;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use FOS\ElasticaBundle\Finder\FinderInterface;
use Sylius\Component\Core\Model\TaxonInterface;
final class ProductAttributesFinder implements ProductAttributesFinderInterface
{
/** @var FinderInterface */
private $attributesFinder;
/** @var QueryBuilderInterface */
private $attributesByTaxonQueryBuilder;
/** @var string */
private $taxonsProperty;
/** @var int */
private $maxAttributes;
public function __construct(
FinderInterface $attributesFinder,
QueryBuilderInterface $attributesByTaxonQueryBuilder,
string $taxonsProperty,
int $maxAttributes = 100
) {
$this->attributesFinder = $attributesFinder;
$this->attributesByTaxonQueryBuilder = $attributesByTaxonQueryBuilder;
$this->taxonsProperty = $taxonsProperty;
$this->maxAttributes = $maxAttributes;
}
public function findByTaxon(TaxonInterface $taxon): ?array
{
$data = [];
$data[$this->taxonsProperty] = strtolower($taxon->getCode());
$query = $this->attributesByTaxonQueryBuilder->buildQuery($data);
return $this->attributesFinder->find($query, $this->maxAttributes);
}
}
In our service definition:
bitbag_sylius_elasticsearch_plugin.finder.product_attributes:
class: App\Service\Search\ProductAttributesFinder
arguments:
- '@fos_elastica.finder.bitbag_attribute_taxons.default'
- '@bitbag_sylius_elasticsearch_plugin.query_builder.product_attributes_by_taxon'
- '%bitbag_es_shop_attribute_taxons_property%'
- 100
Note the name of the service; since this needs to replace the one provided by BitBag we had to replace the named service.
Looks like solved issue, closing.