-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathProductAttributeRepository.php
More file actions
64 lines (52 loc) · 1.93 KB
/
Copy pathProductAttributeRepository.php
File metadata and controls
64 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Resource\Repository\RepositoryInterface;
class ProductAttributeRepository implements ProductAttributeRepositoryInterface
{
public function __construct(
private RepositoryInterface $productAttributeRepository
) {
}
public function getAttributeTypeByName(string $attributeName): string
{
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->productAttributeRepository;
$result = $queryBuilder
->createQueryBuilder('p')
->select('p.type')
->where('p.code = :code')
->setParameter(':code', $attributeName)
->getQuery()
->getOneOrNullResult();
return $result['type'];
}
public function findEnabledWithTranslations(?string $locale): array
{
/** @var EntityRepository $productAttributeRepository */
$productAttributeRepository = $this->productAttributeRepository;
$queryBuilder = $productAttributeRepository->createQueryBuilder('o');
$queryBuilder->andWhere('o.facetDisabled = 0');
if (null !== $locale) {
$queryBuilder
->addSelect('translation')
/** @phpstan-ignore-next-line phpstan can't read relationship correctly */
->leftJoin('o.translations', 'translation', 'ot')
->andWhere('translation.locale = :locale')
->setParameter('locale', $locale)
;
}
return $queryBuilder
->getQuery()
->getResult()
;
}
}