|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Customer\Rule; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\CheckoutRuleScope; |
|
6
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
7
|
|
|
use Shopware\Core\Framework\Rule\CustomFieldRule; |
|
8
|
|
|
use Shopware\Core\Framework\Rule\Exception\UnsupportedOperatorException; |
|
9
|
|
|
use Shopware\Core\Framework\Rule\Rule; |
|
10
|
|
|
use Shopware\Core\Framework\Rule\RuleScope; |
|
11
|
|
|
|
|
12
|
|
|
#[Package('business-ops')] |
|
13
|
|
|
class CustomerCustomFieldRule extends Rule |
|
14
|
|
|
{ |
|
15
|
|
|
final public const RULE_NAME = 'customerCustomField'; |
|
16
|
|
|
|
|
17
|
|
|
protected string|int|bool|null|float $renderedFieldValue = null; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param array<string, string> $renderedField |
|
21
|
|
|
* |
|
22
|
|
|
* @internal |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct( |
|
25
|
|
|
protected string $operator = self::OPERATOR_EQ, |
|
26
|
|
|
protected array $renderedField = [] |
|
27
|
|
|
) { |
|
28
|
|
|
parent::__construct(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @throws UnsupportedOperatorException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function match(RuleScope $scope): bool |
|
35
|
|
|
{ |
|
36
|
|
|
if (!$scope instanceof CheckoutRuleScope) { |
|
37
|
|
|
return false; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$customer = $scope->getSalesChannelContext()->getCustomer(); |
|
41
|
|
|
|
|
42
|
|
|
if ($customer === null) { |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$customFields = $customer->getCustomFields() ?? []; |
|
47
|
|
|
|
|
48
|
|
|
return CustomFieldRule::match($this->renderedField, $this->renderedFieldValue, $this->operator, $customFields); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getConstraints(): array |
|
52
|
|
|
{ |
|
53
|
|
|
return CustomFieldRule::getConstraints($this->renderedField); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|