SyliusElasticsearchPlugin
SyliusElasticsearchPlugin copied to clipboard
Take into account include_all_descendants from sylius_shop bundle configuration
Preconditions:
- have the following taxon structure:
| taxon name | parent |
|---|---|
| root | null |
| perfumes | root |
| eau de toillete | perfumes |
| eau de parfum | perfumes |
- have the following products:
| sku | taxons |
|---|---|
| ABC | eau de toillete |
| DEF | eau de parfum |
- bitbag ElasticSearch plugin is active
Steps to reproduce:
the customer goes to visit the perfumes product listing
What happens:
the product listing is empty
What should happen:
based on the configuration from SyliusShopBundle, the behaviour for BitBagElasticSearch Plugin should be the same as the one from SyliusShopBundle default product listing based on Sylius Grid.
if the config is like below:
sylius_shop:
product_grid:
include_all_descendants: true
the customer should see both products when the product listing for perfumes is displayed
if the config is like below:
sylius_shop:
product_grid:
include_all_descendants: false
The current behaviour is right.
Alternative implementation:
Create an event listener that adds products ABC and DEF to taxon Perfumes and Root when the products are added to the „Eau de perfume” and „Eau de toillete” taxon.
The disadvantage of this approach is that artificial relations that need to be maintained are created, without the knowledge of the admin operator. This might have side effects.
Notes:
The PR that implemented this in Sylius can be reviewed here: https://github.com/Sylius/Sylius/commit/8102395cf2bae36d2cb0080f85099f1c4d87efd5
Side note: this was debated with @vvasiloi on a glass of wine during a Google Hangouts Sessions
I think we can solve it in a simple way. Just add a recursive for that will build an array of taxons to root. E.g
private function getTreeFromTaxon(?TaxonInterface $taxon): array
{
if (null === $taxon) {
return [];
}
$result[] = $taxon->getCode();
if (null !== $parent = $taxon->getParent()) {
$result = array_merge($result, $this->getTreeFromTaxon($parent));
}
return $result;
}
The function can be added here https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/master/src/PropertyBuilder/Mapper/ProductTaxonsMapper.php#L27
@patrick477 it should go the other way... I already implemented this in my current project, but looks like contributing to this plugin is a waste of my time, so I'm not bothering.
Closed discussion, if there is something else to add - please reopen