Skip to content

Commit

Permalink
Add fix for phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Kostrubiec committed Jul 9, 2024
1 parent 63b9c8b commit f5a7bbc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Repository/ProductAttributeValueRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,46 @@

namespace BitBag\SyliusElasticsearchPlugin\Repository;

use Doctrine\ORM\EntityRepository;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface as BaseAttributeValueRepositoryInterface;
use Sylius\Component\Taxonomy\Model\Taxon;

class ProductAttributeValueRepository implements ProductAttributeValueRepositoryInterface
{
public function __construct(
private BaseAttributeValueRepositoryInterface $baseAttributeValueRepository,
private BaseAttributeValueRepositoryInterface|EntityRepository $baseAttributeValueRepository,
private bool $includeAllDescendants
) {
}

public function getUniqueAttributeValues(AttributeInterface $productAttribute, Taxon $taxon): array
{
$queryBuilder = $this->baseAttributeValueRepository->createQueryBuilder('o');
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->baseAttributeValueRepository;

/** @var string|null $storageType */
$storageType = $productAttribute->getStorageType();

$queryBuilder
->createQueryBuilder('o')
->join('o.subject', 'p', 'WITH', 'p.enabled = 1')
->join('p.productTaxons', 't', 'WITH', 't.product = p.id')
->select('o.localeCode, o.' . $storageType . ' as value')
->andWhere('t.taxon = :taxon');

if (true === $this->includeAllDescendants) {
$queryBuilder->innerJoin('t.taxon', 'taxon')
$queryBuilder
->createQueryBuilder('o')
->innerJoin('t.taxon', 'taxon')
->orWhere('taxon.left >= :taxonLeft and taxon.right <= :taxonRight and taxon.root = :taxonRoot')
->setParameter('taxonLeft', $taxon->getLeft())
->setParameter('taxonRight', $taxon->getRight())
->setParameter('taxonRoot', $taxon->getRoot());
}

return $queryBuilder
->createQueryBuilder('o')
->andWhere('o.attribute = :attribute')
->groupBy('o.' . $storageType)
->addGroupBy('o.localeCode')
Expand Down

0 comments on commit f5a7bbc

Please sign in to comment.