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\ProductBundle\Doctrine\ORM; |
13
|
|
|
|
14
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
15
|
|
|
use Sylius\Component\Core\Model\Product; |
16
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
17
|
|
|
use Sylius\Component\Product\Model\ProductVariantInterface; |
18
|
|
|
use Sylius\Component\Product\Repository\ProductVariantRepositoryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Alexandre Bacco <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ProductVariantRepository extends EntityRepository implements ProductVariantRepositoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function createQueryBuilderByProductId($locale, $productId) |
29
|
|
|
{ |
30
|
|
|
return $this->createQueryBuilder('o') |
31
|
|
|
->innerJoin('o.translations', 'translation') |
32
|
|
|
->andWhere('translation.locale = :locale') |
33
|
|
|
->andWhere('o.product = :productId') |
34
|
|
|
->setParameter('locale', $locale) |
35
|
|
|
->setParameter('productId', $productId) |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function createQueryBuilderByProductCode($locale, $productCode) |
43
|
|
|
{ |
44
|
|
|
return $this->createQueryBuilder('o') |
45
|
|
|
->innerJoin('o.translations', 'translation') |
46
|
|
|
->innerJoin('o.product', 'product') |
47
|
|
|
->andWhere('translation.locale = :locale') |
48
|
|
|
->andWhere('product.code = :productCode') |
49
|
|
|
->setParameter('locale', $locale) |
50
|
|
|
->setParameter('productCode', $productCode) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
|
|
public function findByName($name, $locale) |
58
|
|
|
{ |
59
|
|
|
return $this->createQueryBuilder('o') |
60
|
|
|
->innerJoin('o.translations', 'translation') |
61
|
|
|
->andWhere('translation.name = :name') |
62
|
|
|
->andWhere('translation.locale = :locale') |
63
|
|
|
->setParameter('name', $name) |
64
|
|
|
->setParameter('locale', $locale) |
65
|
|
|
->getQuery() |
66
|
|
|
->getResult() |
67
|
|
|
; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function findByNameAndProduct($name, $locale, ProductInterface $product) |
74
|
|
|
{ |
75
|
|
|
return $this->createQueryBuilder('o') |
76
|
|
|
->innerJoin('o.translations', 'translation') |
77
|
|
|
->andWhere('translation.name = :name') |
78
|
|
|
->andWhere('translation.locale = :locale') |
79
|
|
|
->andWhere('o.product = :product') |
80
|
|
|
->setParameter('name', $name) |
81
|
|
|
->setParameter('locale', $locale) |
82
|
|
|
->setParameter('product', $product) |
83
|
|
|
->getQuery() |
84
|
|
|
->getResult() |
85
|
|
|
; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function findOneByCodeAndProductCode($code, $productCode) |
92
|
|
|
{ |
93
|
|
|
return $this->createQueryBuilder('o') |
94
|
|
|
->innerJoin('o.product', 'product') |
95
|
|
|
->where('product.code = :productCode') |
96
|
|
|
->andWhere('o.code = :code') |
97
|
|
|
->setParameter('productCode', $productCode) |
98
|
|
|
->setParameter('code', $code) |
99
|
|
|
->getQuery() |
100
|
|
|
->getOneOrNullResult() |
101
|
|
|
; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function findOneByIdAndProductId($id, $productId) |
108
|
|
|
{ |
109
|
|
|
return $this->createQueryBuilder('o') |
110
|
|
|
->where('o.product = :productId') |
111
|
|
|
->andWhere('o.id = :id') |
112
|
|
|
->setParameter('productId', $productId) |
113
|
|
|
->setParameter('id', $id) |
114
|
|
|
->getQuery() |
115
|
|
|
->getOneOrNullResult() |
116
|
|
|
; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|