1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusElasticsearchPlugin\Repository; |
14
|
|
|
|
15
|
|
|
use Doctrine\ORM\EntityRepository; |
16
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
17
|
|
|
use Sylius\Component\Attribute\Model\AttributeInterface; |
18
|
|
|
use Sylius\Component\Core\Repository\ProductRepositoryInterface; |
19
|
|
|
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface as BaseTaxonRepositoryInterface; |
20
|
|
|
|
21
|
|
|
final class TaxonRepository implements TaxonRepositoryInterface |
22
|
|
|
{ |
23
|
|
|
/** @var BaseTaxonRepositoryInterface|EntityRepository */ |
24
|
|
|
private $baseTaxonRepository; |
25
|
|
|
|
26
|
|
|
/** @var ProductRepositoryInterface|EntityRepository */ |
27
|
|
|
private $productRepository; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
private $productTaxonEntityClass; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
private $productAttributeEntityClass; |
34
|
|
|
|
35
|
|
|
public function __construct( |
36
|
|
|
BaseTaxonRepositoryInterface $baseTaxonRepository, |
37
|
|
|
ProductRepositoryInterface $productRepository, |
38
|
|
|
string $productTaxonEntityClass, |
39
|
|
|
string $productAttributeEntityClass |
40
|
|
|
) { |
41
|
|
|
$this->baseTaxonRepository = $baseTaxonRepository; |
42
|
|
|
$this->productRepository = $productRepository; |
43
|
|
|
$this->productTaxonEntityClass = $productTaxonEntityClass; |
44
|
|
|
$this->productAttributeEntityClass = $productAttributeEntityClass; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array |
48
|
|
|
{ |
49
|
|
|
return $this->baseTaxonRepository |
50
|
|
|
->createQueryBuilder('t') |
|
|
|
|
51
|
|
|
->distinct(true) |
52
|
|
|
->select('t') |
53
|
|
|
->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id') |
54
|
|
|
->where( |
55
|
|
|
'pt.product IN(' . |
56
|
|
|
$this |
57
|
|
|
->productRepository->createQueryBuilder('p') |
|
|
|
|
58
|
|
|
->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id') |
59
|
|
|
->where('pav.attribute = :attribute') |
60
|
|
|
->getQuery() |
61
|
|
|
->getDQL() |
62
|
|
|
. ')' |
63
|
|
|
) |
64
|
|
|
->setParameter(':attribute', $attribute) |
65
|
|
|
->getQuery() |
66
|
|
|
->getResult() |
67
|
|
|
; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.