1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM; |
13
|
|
|
|
14
|
|
|
use Doctrine\ORM\QueryBuilder; |
15
|
|
|
use Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductRepository as BaseProductRepository; |
16
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
18
|
|
|
use Sylius\Component\Core\Repository\ProductRepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
22
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ProductRepository extends BaseProductRepository implements ProductRepositoryInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function createListQueryBuilder($locale, $taxonId = null) |
30
|
|
|
{ |
31
|
|
|
$queryBuilder = $this->createQueryBuilder('o'); |
32
|
|
|
|
33
|
|
|
$queryBuilder |
34
|
|
|
->addSelect('translation') |
35
|
|
|
->leftJoin('o.translations', 'translation') |
36
|
|
|
->andWhere('translation.locale = :locale') |
37
|
|
|
->setParameter('locale', $locale) |
38
|
|
|
; |
39
|
|
|
|
40
|
|
|
if (null !== $taxonId) { |
41
|
|
|
$queryBuilder |
42
|
|
|
->innerJoin('o.productTaxons', 'productTaxon') |
43
|
|
|
->andWhere('productTaxon.taxon = :taxonId') |
44
|
|
|
->setParameter('taxonId', $taxonId) |
45
|
|
|
; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $queryBuilder; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function createQueryBuilderByChannelAndTaxonId(ChannelInterface $channel, $taxonId, $locale) |
55
|
|
|
{ |
56
|
|
|
return $this->createQueryBuilder('o') |
57
|
|
|
->addSelect('translation') |
58
|
|
|
->leftJoin('o.translations', 'translation') |
59
|
|
|
->innerJoin('o.productTaxons', 'productTaxon') |
60
|
|
|
->innerJoin('o.channels', 'channel') |
61
|
|
|
->andWhere('translation.locale = :locale') |
62
|
|
|
->andWhere('productTaxon.taxon = :taxonId') |
63
|
|
|
->andWhere('channel = :channel') |
64
|
|
|
->andWhere('o.enabled = true') |
65
|
|
|
->setParameter('locale', $locale) |
66
|
|
|
->setParameter('taxonId', $taxonId) |
67
|
|
|
->setParameter('channel', $channel) |
68
|
|
|
; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function findLatestByChannel(ChannelInterface $channel, $count) |
75
|
|
|
{ |
76
|
|
|
return $this->createQueryBuilder('o') |
77
|
|
|
->innerJoin('o.channels', 'channel') |
78
|
|
|
->addOrderBy('o.createdAt', 'desc') |
79
|
|
|
->andWhere('o.enabled = true') |
80
|
|
|
->andWhere('channel = :channel') |
81
|
|
|
->setParameter('channel', $channel) |
82
|
|
|
->setMaxResults($count) |
83
|
|
|
->getQuery() |
84
|
|
|
->getResult() |
85
|
|
|
; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function findOneBySlugAndChannel($slug, ChannelInterface $channel) |
92
|
|
|
{ |
93
|
|
|
return $this->createQueryBuilder('o') |
94
|
|
|
->leftJoin('o.translations', 'translation') |
95
|
|
|
->innerJoin('o.channels', 'channel') |
96
|
|
|
->andWhere('translation.slug = :slug') |
97
|
|
|
->andWhere('channel = :channel') |
98
|
|
|
->andWhere('o.enabled = true') |
99
|
|
|
->setParameter('slug', $slug) |
100
|
|
|
->setParameter('channel', $channel) |
101
|
|
|
->getQuery() |
102
|
|
|
->getOneOrNullResult() |
103
|
|
|
; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function findOneBySlug($slug) |
110
|
|
|
{ |
111
|
|
|
return $this->createQueryBuilder('o') |
112
|
|
|
->leftJoin('o.translations', 'translation') |
113
|
|
|
->andWhere('translation.slug = :slug') |
114
|
|
|
->andWhere('o.enabled = true') |
115
|
|
|
->setParameter('slug', $slug) |
116
|
|
|
->getQuery() |
117
|
|
|
->getOneOrNullResult() |
118
|
|
|
; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|