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\PropertyBuilder; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusElasticsearchPlugin\Formatter\StringFormatterInterface; |
16
|
|
|
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface; |
17
|
|
|
use BitBag\SyliusElasticsearchPlugin\PropertyValueResolver\AttributeValueResolverInterface; |
|
|
|
|
18
|
|
|
use Elastica\Document; |
19
|
|
|
use FOS\ElasticaBundle\Event\TransformEvent; |
20
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
21
|
|
|
|
22
|
|
|
final class AttributeBuilder extends AbstractBuilder |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ConcatedNameResolverInterface |
26
|
|
|
*/ |
27
|
|
|
private $attributeNameResolver; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var AttributeValueResolverInterface |
31
|
|
|
*/ |
32
|
|
|
private $attributeValueResolver; |
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var StringFormatterInterface |
36
|
|
|
*/ |
37
|
|
|
private $stringFormatter; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param ConcatedNameResolverInterface $attributeNameResolver |
41
|
|
|
* @param StringFormatterInterface $stringFormatter |
42
|
|
|
*/ |
43
|
|
|
public function __construct( |
44
|
|
|
ConcatedNameResolverInterface $attributeNameResolver, |
45
|
|
|
StringFormatterInterface $stringFormatter |
46
|
|
|
) |
47
|
|
|
{ |
48
|
|
|
$this->attributeNameResolver = $attributeNameResolver; |
49
|
|
|
$this->stringFormatter = $stringFormatter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param TransformEvent $event |
54
|
|
|
*/ |
55
|
|
|
public function buildProperty(TransformEvent $event): void |
56
|
|
|
{ |
57
|
|
|
/** @var ProductInterface $product */ |
58
|
|
|
$product = $event->getObject(); |
59
|
|
|
|
60
|
|
|
if (!$product instanceof ProductInterface) { |
|
|
|
|
61
|
|
|
return; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$document = $event->getDocument(); |
65
|
|
|
|
66
|
|
|
$this->resolveProductAttributes($product, $document); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param ProductInterface $product |
71
|
|
|
* @param Document $document |
72
|
|
|
*/ |
73
|
|
|
private function resolveProductAttributes(ProductInterface $product, Document $document): void |
74
|
|
|
{ |
75
|
|
|
foreach ($product->getAttributes() as $attributeValue) { |
76
|
|
|
$attributeCode = $attributeValue->getAttribute()->getCode(); |
77
|
|
|
$index = $this->attributeNameResolver->resolvePropertyName($attributeCode); |
78
|
|
|
$value = $attributeValue->getValue(); |
79
|
|
|
$attributes = []; |
80
|
|
|
|
81
|
|
|
if (is_array($value)) { |
82
|
|
|
foreach ($value as $singleElement) { |
83
|
|
|
$attributes[] = $this->stringFormatter->formatToLowercaseWithoutSpaces((string) $singleElement); |
84
|
|
|
} |
85
|
|
|
} else { |
86
|
|
|
$value = is_string($value) ? $this->stringFormatter->formatToLowercaseWithoutSpaces($value) : $value; |
87
|
|
|
$attributes[] = $value; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$document->set($index, $attributes); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths