|
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\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
|
10
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
11
|
|
|
|
|
12
|
|
|
class VendorRepository extends EntityRepository implements VendorRepositoryInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
|
|
public function createShopListQueryBuilder( |
|
18
|
|
|
ChannelInterface $channel, |
|
19
|
|
|
array $sorting = [] |
|
20
|
|
|
): QueryBuilder { |
|
21
|
|
|
return $this->findByEnabledQueryBuilder($channel); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function findByEnabledQueryBuilder(?ChannelInterface $channel): QueryBuilder |
|
28
|
|
|
{ |
|
29
|
|
|
$queryBuilder = $this->createQueryBuilder('o') |
|
30
|
|
|
->andWhere('o.enabled = :enabled') |
|
31
|
|
|
->setParameter('enabled', true) |
|
32
|
|
|
; |
|
33
|
|
|
|
|
34
|
|
|
if ($channel instanceof ChannelInterface) { |
|
35
|
|
|
$queryBuilder->innerJoin('o.channels', 'channel') |
|
36
|
|
|
->andWhere('channel = :channel') |
|
37
|
|
|
->setParameter('channel', $channel) |
|
38
|
|
|
; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return $queryBuilder; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
public function findByChannel(ChannelInterface $channel): array |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->findByEnabledQueryBuilder($channel)->getQuery()->getResult(); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function findOneBySlug(string $slug, string $locale): ?VendorInterface |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->createQueryBuilder('o') |
|
|
|
|
|
|
58
|
|
|
->addSelect('translation') |
|
59
|
|
|
->innerJoin('o.translations', 'translation') |
|
60
|
|
|
->andWhere('o.slug = :slug') |
|
61
|
|
|
->andWhere('o.enabled = true') |
|
62
|
|
|
->andWhere('translation.locale = :locale') |
|
63
|
|
|
->setParameter('slug', $slug) |
|
64
|
|
|
->setParameter('locale', $locale) |
|
65
|
|
|
->getQuery() |
|
66
|
|
|
->getOneOrNullResult() |
|
67
|
|
|
; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|