|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Checkout\Test\Cart\Promotion\Helpers\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Cart\Rule\LineItemRule; |
|
6
|
|
|
use Shopware\Core\Checkout\Promotion\Aggregate\PromotionSetGroup\PromotionSetGroupEntity; |
|
7
|
|
|
use Shopware\Core\Content\Rule\RuleCollection; |
|
8
|
|
|
use Shopware\Core\Defaults; |
|
9
|
|
|
use Shopware\Core\Framework\Rule\Rule; |
|
10
|
|
|
use Shopware\Core\Framework\Uuid\Uuid; |
|
11
|
|
|
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
13
|
|
|
|
|
14
|
|
|
trait PromotionSetGroupTestFixtureBehaviour |
|
15
|
|
|
{ |
|
16
|
|
|
private function createSetGroup(string $packagerKey, float $value, string $sorterKey, array $rules): PromotionSetGroupEntity |
|
17
|
|
|
{ |
|
18
|
|
|
$group = new PromotionSetGroupEntity(); |
|
19
|
|
|
$group->setId(Uuid::randomBytes()); |
|
20
|
|
|
|
|
21
|
|
|
$group->setPackagerKey($packagerKey); |
|
22
|
|
|
$group->setValue($value); |
|
23
|
|
|
$group->setSorterKey($sorterKey); |
|
24
|
|
|
$group->setSetGroupRules(new RuleCollection($rules)); |
|
25
|
|
|
|
|
26
|
|
|
return $group; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
private function createSetGroupWithRuleFixture(string $groupId, string $packagerKey, float $value, string $sorterKey, string $promotionId, string $ruleId, ContainerInterface $container): string |
|
30
|
|
|
{ |
|
31
|
|
|
$context = $container->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), Defaults::SALES_CHANNEL); |
|
32
|
|
|
|
|
33
|
|
|
$repository = $container->get('promotion_setgroup.repository'); |
|
34
|
|
|
|
|
35
|
|
|
$data = [ |
|
36
|
|
|
'id' => $groupId, |
|
37
|
|
|
'promotionId' => $promotionId, |
|
38
|
|
|
'packagerKey' => $packagerKey, |
|
39
|
|
|
'sorterKey' => $sorterKey, |
|
40
|
|
|
'value' => $value, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
$repository->create([$data], $context->getContext()); |
|
44
|
|
|
|
|
45
|
|
|
$ruleRepository = $container->get('promotion_setgroup_rule.repository'); |
|
46
|
|
|
|
|
47
|
|
|
$dataAssoc = [ |
|
48
|
|
|
'setgroupId' => $groupId, |
|
49
|
|
|
'ruleId' => $ruleId, |
|
50
|
|
|
]; |
|
51
|
|
|
|
|
52
|
|
|
$ruleRepository->create([$dataAssoc], $context->getContext()); |
|
53
|
|
|
|
|
54
|
|
|
return $groupId; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
private function createRule(string $name, array $lineItemIds, ContainerInterface $container): string |
|
58
|
|
|
{ |
|
59
|
|
|
$context = $container->get(SalesChannelContextFactory::class)->create(Uuid::randomHex(), Defaults::SALES_CHANNEL); |
|
60
|
|
|
$ruleRepository = $container->get('rule.repository'); |
|
61
|
|
|
$conditionRepository = $container->get('rule_condition.repository'); |
|
62
|
|
|
|
|
63
|
|
|
$ruleId = Uuid::randomHex(); |
|
64
|
|
|
$ruleRepository->create( |
|
65
|
|
|
[['id' => $ruleId, 'name' => $name, 'priority' => 1]], |
|
66
|
|
|
$context->getContext() |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$id = Uuid::randomHex(); |
|
70
|
|
|
$conditionRepository->create([ |
|
71
|
|
|
[ |
|
72
|
|
|
'id' => $id, |
|
73
|
|
|
'type' => (new LineItemRule())->getName(), |
|
74
|
|
|
'ruleId' => $ruleId, |
|
75
|
|
|
'value' => [ |
|
76
|
|
|
'identifiers' => $lineItemIds, |
|
77
|
|
|
'operator' => Rule::OPERATOR_EQ, |
|
78
|
|
|
], |
|
79
|
|
|
], |
|
80
|
|
|
], $context->getContext()); |
|
81
|
|
|
|
|
82
|
|
|
return $ruleId; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|