|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BitBag\SyliusElasticsearchPlugin\EntityRepository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
8
|
|
|
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductRepository; |
|
9
|
|
|
use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository as BaseTaxonRepository; |
|
10
|
|
|
use Sylius\Component\Attribute\Model\AttributeInterface; |
|
11
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
|
12
|
|
|
use Sylius\Component\Core\Repository\ProductRepositoryInterface; |
|
13
|
|
|
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface as BaseTaxonRepositoryInterface; |
|
14
|
|
|
|
|
15
|
|
|
class TaxonRepository implements TaxonRepositoryInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var BaseTaxonRepository |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $taxonRepository; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var ProductRepository |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $productRepository; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $productTaxonEntityClass; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $productAttributeEntityClass; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* TaxonRepository constructor. |
|
39
|
|
|
* |
|
40
|
|
|
* @param BaseTaxonRepositoryInterface $taxonRepository |
|
41
|
|
|
* @param ProductRepositoryInterface $productRepository |
|
42
|
|
|
* @param string $productTaxonEntityClass |
|
43
|
|
|
* @param string $productAttributeEntityClass |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
BaseTaxonRepositoryInterface $taxonRepository, |
|
47
|
|
|
ProductRepositoryInterface $productRepository, |
|
48
|
|
|
string $productTaxonEntityClass, |
|
49
|
|
|
string $productAttributeEntityClass |
|
50
|
|
|
) { |
|
51
|
|
|
$this->taxonRepository = $taxonRepository; |
|
|
|
|
|
|
52
|
|
|
$this->productRepository = $productRepository; |
|
|
|
|
|
|
53
|
|
|
$this->productTaxonEntityClass = $productTaxonEntityClass; |
|
54
|
|
|
$this->productAttributeEntityClass = $productAttributeEntityClass; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param AttributeInterface $attribute |
|
59
|
|
|
* |
|
60
|
|
|
* @return array|TaxonInterface[] |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->taxonRepository |
|
65
|
|
|
->createQueryBuilder('t') |
|
66
|
|
|
->distinct(true) |
|
67
|
|
|
->select('t') |
|
68
|
|
|
->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id') |
|
69
|
|
|
->where( |
|
70
|
|
|
'pt.product IN(' . |
|
71
|
|
|
$this |
|
72
|
|
|
->productRepository->createQueryBuilder('p') |
|
73
|
|
|
->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id') |
|
74
|
|
|
->where('pav.attribute = :attribute') |
|
75
|
|
|
->getQuery() |
|
76
|
|
|
->getDQL() |
|
77
|
|
|
. ')' |
|
78
|
|
|
) |
|
79
|
|
|
->setParameter(':attribute', $attribute) |
|
80
|
|
|
->getQuery() |
|
81
|
|
|
->getResult(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.