Sylius: Taxon root is not being checked in ProductRepository

Created on 21 Jul 2016  Â·  1Comment  Â·  Source: Sylius/Sylius

In ProductRepository inside method createByTaxonPaginator tree root condition is missing. Because of this, products which are not assigned to the given taxon will still be fetched from db.

I believe this method should be:

    public function createByTaxonPaginator(TaxonInterface $taxon, array $criteria = [])
    {
        $queryBuilder = $this->createQueryBuilder('o');
        $queryBuilder
            ->innerJoin('o.taxons', 'taxon')
            ->andWhere($queryBuilder->expr()->orX(
                'taxon = :taxon',
                ':left < taxon.left AND taxon.right < :right'
            ))
            ->andWhere('taxon.root = :tree_root')
            ->setParameter('tree_root', $taxon->isRoot() ? $taxon->getId() : $taxon->getRoot()->getId())
            ->setParameter('taxon', $taxon)
            ->setParameter('left', $taxon->getLeft())
            ->setParameter('right', $taxon->getRight())
        ;

        $this->applyCriteria($queryBuilder, $criteria);

        return $this->getPaginator($queryBuilder);
    }

Tell me If I got this wrong, but as far as I can see tree_left and tree_right condition will match taxons even they are not into the given taxon tree.

Thanks!

Potential Bug

Most helpful comment

Are you open for PR?

>All comments

Are you open for PR?

Was this page helpful?
0 / 5 - 0 ratings