Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszpietrzak1994 committed Aug 10, 2018
1 parent 513b6c6 commit da8f987
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
30 changes: 8 additions & 22 deletions src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php
Expand Up @@ -70,16 +70,17 @@ public function createShopListQueryBuilder(
TaxonInterface $taxon,
string $locale,
array $sorting = [],
bool $reproduceTaxonomyTree = false
bool $includeAllDescendants = false
): QueryBuilder {
$queryBuilder = $this->createQueryBuilder('o')
->addSelect('translation')
->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->innerJoin('o.productTaxons', 'productTaxon');
->innerJoin('o.productTaxons', 'productTaxon')
->innerJoin('productTaxon.taxon', 'taxon');

if ($reproduceTaxonomyTree) {
$queryBuilder->orWhere('productTaxon.taxon = :taxon');
$this->reproduceTaxonomyTree($taxon, $queryBuilder);
if ($includeAllDescendants) {
$queryBuilder->andWhere('taxon.left >= :taxonLeft');
$queryBuilder->andWhere('taxon.right <= :taxonRight');
} else {
$queryBuilder->andWhere('productTaxon.taxon = :taxon');
}
Expand All @@ -88,7 +89,8 @@ public function createShopListQueryBuilder(
->andWhere(':channel MEMBER OF o.channels')
->andWhere('o.enabled = true')
->setParameter('locale', $locale)
->setParameter('taxon', $taxon)
->setParameter('taxonLeft', $taxon->getLeft())
->setParameter('taxonRight', $taxon->getRight())
->setParameter('channel', $channel)
;

Expand Down Expand Up @@ -180,20 +182,4 @@ public function findOneByCode(string $code): ?ProductInterface
->getOneOrNullResult()
;
}

private function reproduceTaxonomyTree(TaxonInterface $taxon, QueryBuilder $queryBuilder): void
{
if (!$taxon->hasChildren()) {
$parameter = 'taxonChild' . $taxon->getCode();

$queryBuilder->orWhere('productTaxon.taxon = :' . $parameter);
$queryBuilder->setParameter($parameter, $taxon);

return;
}

foreach ($taxon->getChildren() as $taxonChild) {
$this->reproduceTaxonomyTree($taxonChild, $queryBuilder);
}
}
}
Expand Up @@ -15,7 +15,7 @@ sylius_grid:
taxon: "expr:notFoundOnNull(service('sylius.repository.taxon').findOneBySlug($slug, service('sylius.context.locale').getLocaleCode()))"
locale: "expr:service('sylius.context.locale').getLocaleCode()"
sorting: "expr:service('request_stack').getCurrentRequest().get('sorting', [])"
reproduceTaxonomyTree: true
includeAllDescendants: true
sorting:
position: asc
limits: [9, 18, 27]
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function createListQueryBuilder(string $locale, $taxonId = null): QueryBu
* @param TaxonInterface $taxon
* @param string $locale
* @param array $sorting
* @param bool $reproduceTaxonomyTree
* @param bool $includeAllDescendants
*
* @return QueryBuilder
*/
Expand All @@ -43,7 +43,7 @@ public function createShopListQueryBuilder(
TaxonInterface $taxon,
string $locale,
array $sorting = [],
bool $reproduceTaxonomyTree = false
bool $includeAllDescendants = false
): QueryBuilder;

/**
Expand Down

0 comments on commit da8f987

Please sign in to comment.