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\Rule; |
8
|
|
|
use Shopware\Core\Framework\Rule\RuleComparison; |
9
|
|
|
use Shopware\Core\Framework\Rule\RuleConfig; |
10
|
|
|
use Shopware\Core\Framework\Rule\RuleConstraints; |
11
|
|
|
use Shopware\Core\Framework\Rule\RuleScope; |
12
|
|
|
|
13
|
|
|
#[Package('business-ops')] |
14
|
|
|
class NumberOfReviewsRule extends Rule |
15
|
|
|
{ |
16
|
|
|
final public const RULE_NAME = 'numberOfReviews'; |
17
|
|
|
|
18
|
|
|
protected string $operator; |
19
|
|
|
|
20
|
|
|
protected int $count; |
21
|
|
|
|
22
|
|
|
public function match(RuleScope $scope): bool |
23
|
|
|
{ |
24
|
|
|
if (!$scope instanceof CheckoutRuleScope) { |
25
|
|
|
return false; |
26
|
|
|
} |
27
|
|
|
if (!$customer = $scope->getSalesChannelContext()->getCustomer()) { |
28
|
|
|
return RuleComparison::isNegativeOperator($this->operator); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$numberOfReviews = $customer->getReviewCount(); |
32
|
|
|
|
33
|
|
|
return RuleComparison::numeric($numberOfReviews, $this->count, $this->operator); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getConstraints(): array |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
'count' => RuleConstraints::int(), |
40
|
|
|
'operator' => RuleConstraints::numericOperators(false), |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getConfig(): RuleConfig |
45
|
|
|
{ |
46
|
|
|
return (new RuleConfig()) |
47
|
|
|
->operatorSet(RuleConfig::OPERATOR_SET_NUMBER) |
48
|
|
|
->intField('count'); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|