Completed
Push — master ( 142849...183104 )
by
unknown
05:50
created

ProductRepositoryTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 15
c 1
b 1
f 0
dl 0
loc 34
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createShopListByVendorQueryBuilder() 0 22 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusVendorPlugin\Repository;
6
7
use Doctrine\ORM\QueryBuilder;
8
use Odiseo\SyliusVendorPlugin\Entity\VendorInterface;
9
use Sylius\Component\Core\Model\ChannelInterface;
10
11
trait ProductRepositoryTrait
12
{
13
    /**
14
     * @param $alias
15
     * @param null $indexBy
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $indexBy is correct as it would always require null to be passed?
Loading history...
16
     * @return mixed
17
     */
18
    abstract public function createQueryBuilder($alias, $indexBy = null);
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function createShopListByVendorQueryBuilder(
24
        ChannelInterface $channel,
25
        VendorInterface $vendor,
26
        string $locale
27
    ): QueryBuilder {
28
        $queryBuilder = $this->createQueryBuilder('o')
29
            ->distinct()
30
            ->addSelect('translation')
31
            ->addSelect('productTaxon')
32
            ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
33
            ->innerJoin('o.productTaxons', 'productTaxon');
34
35
        $queryBuilder
36
            ->andWhere(':channel MEMBER OF o.channels')
37
            ->andWhere('o.enabled = true')
38
            ->andWhere('o.vendor = :vendor')
39
            ->setParameter('locale', $locale)
40
            ->setParameter('channel', $channel)
41
            ->setParameter('vendor', $vendor)
42
        ;
43
44
        return $queryBuilder;
45
    }
46
}
47