|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Cart\Rule; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Cart\LineItem\LineItem; |
|
6
|
|
|
use Shopware\Core\Content\Property\Aggregate\PropertyGroupOption\PropertyGroupOptionDefinition; |
|
7
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
8
|
|
|
use Shopware\Core\Framework\Rule\Rule; |
|
9
|
|
|
use Shopware\Core\Framework\Rule\RuleComparison; |
|
10
|
|
|
use Shopware\Core\Framework\Rule\RuleConfig; |
|
11
|
|
|
use Shopware\Core\Framework\Rule\RuleConstraints; |
|
12
|
|
|
use Shopware\Core\Framework\Rule\RuleScope; |
|
13
|
|
|
|
|
14
|
|
|
#[Package('business-ops')] |
|
15
|
|
|
class LineItemVariantValueRule extends Rule |
|
16
|
|
|
{ |
|
17
|
|
|
public const RULE_NAME = 'cartLineItemVariantValue'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @internal |
|
21
|
|
|
* |
|
22
|
|
|
* @param list<string>|null $identifiers |
|
|
|
|
|
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct( |
|
25
|
|
|
public string $operator = Rule::OPERATOR_EQ, |
|
26
|
|
|
public ?array $identifiers = null |
|
27
|
|
|
) { |
|
28
|
|
|
parent::__construct(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function getConstraints(): array |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
|
|
'operator' => RuleConstraints::uuidOperators(false), |
|
35
|
|
|
'identifiers' => RuleConstraints::uuids(), |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function match(RuleScope $scope): bool |
|
40
|
|
|
{ |
|
41
|
|
|
if ($scope instanceof LineItemScope) { |
|
42
|
|
|
return $this->matchLineItem($scope->getLineItem()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (!$scope instanceof CartRuleScope) { |
|
46
|
|
|
return false; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
foreach ($scope->getCart()->getLineItems()->filterGoodsFlat() as $item) { |
|
50
|
|
|
if ($this->matchLineItem($item)) { |
|
51
|
|
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function matchLineItem(LineItem $lineItem): bool |
|
59
|
|
|
{ |
|
60
|
|
|
/** |
|
61
|
|
|
* @var list<string> $value |
|
62
|
|
|
*/ |
|
63
|
|
|
$value = $lineItem->getPayloadValue('optionIds') ?? []; |
|
64
|
|
|
|
|
65
|
|
|
return RuleComparison::uuids( |
|
66
|
|
|
$value, |
|
|
|
|
|
|
67
|
|
|
$this->identifiers, |
|
68
|
|
|
$this->operator |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getConfig(): RuleConfig |
|
73
|
|
|
{ |
|
74
|
|
|
return (new RuleConfig()) |
|
75
|
|
|
->operatorSet(RuleConfig::OPERATOR_SET_STRING, false, true) |
|
76
|
|
|
->entitySelectField('identifiers', PropertyGroupOptionDefinition::ENTITY_NAME, true); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
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