Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple taxons for one option #136

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/PropertyBuilder/OptionTaxonsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ public function consumeEvent(TransformEvent $event): void
/** @var ProductOptionValueInterface $optionValue */
foreach ($optionValues as $optionValue) {
$option = $optionValue->getOption();
$productVariant = $this->productVariantRepository->findOneByOptionValue($optionValue);
$productVariants = $this->productVariantRepository->findOneByOptionValue($optionValue);

if (null === $productVariant) {
continue;
}
foreach ($productVariants as $productVariant) {
if (null === $productVariant) {
continue;
}

/** @var ProductInterface $product */
$product = $productVariant->getProduct();
/** @var ProductInterface $product */
$product = $productVariant->getProduct();

if ($documentProductOption === $option && $product->isEnabled()) {
$taxons = $this->productTaxonsMapper->mapToUniqueCodes($product);
if ($documentProductOption === $option && $product->isEnabled()) {
$taxons = $this->productTaxonsMapper->mapToUniqueCodes($product);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/QueryBuilder/ContainsNameQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use Elastica\Query\AbstractQuery;
use Elastica\Query\Match;
use Elastica\Query\MatchQuery;
use Sylius\Component\Locale\Context\LocaleContextInterface;

final class ContainsNameQueryBuilder implements QueryBuilderInterface
Expand Down Expand Up @@ -47,7 +47,7 @@ public function buildQuery(array $data): ?AbstractQuery
return null;
}

$nameQuery = new Match();
$nameQuery = new MatchQuery();

$nameQuery->setFieldQuery($propertyName, $name);
$nameQuery->setFieldFuzziness($propertyName, 2);
Expand Down
5 changes: 2 additions & 3 deletions src/Repository/ProductVariantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ public function __construct(BaseProductVariantRepositoryInterface $baseProductVa
$this->baseProductVariantRepository = $baseProductVariantRepository;
}

public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface
public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): array
{
return $this->baseProductVariantRepository->createQueryBuilder('o')
->where(':optionValue MEMBER OF o.optionValues')
->setParameter('optionValue', $productOptionValue)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
->getResult()
;
}
}
2 changes: 1 addition & 1 deletion src/Repository/ProductVariantRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@

interface ProductVariantRepositoryInterface
{
public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface;
public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): array;
}