WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 4a80b63

Browse files
authored
Merge pull request #6258 from systemfriend-tsuji/feature/fix_purchase_flow_priority
PurchaseFlowのPriorityが意図しないソート順になっている場合がある #6257 の修正
2 parents f0adfec + 4a7d085 commit 4a80b63

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/Eccube/DependencyInjection/Compiler/PurchaseFlowPass.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,32 @@ public function process(ContainerBuilder $container)
5050
*/
5151
foreach ($this->getProcessorTags() as $tag => $methodName) {
5252
/** @var Reference $id */
53+
$allMethod = [];
54+
$i = 0;
55+
// findAndSortTaggedServicesでは、flow_typeごとのソートができないため
56+
// その並びをもとに配列に入れ直す
5357
foreach ($this->findAndSortTaggedServices($tag, $container) as $id) {
5458
$def = $container->findDefinition($id);
5559
foreach ($def->getTag($tag) as $attributes) {
5660
if (isset($attributes['flow_type'])) {
57-
/**
58-
* @var string $flowType
59-
* @var Definition $purchaseFlowDef
60-
*/
61-
foreach ($flowTypes as $flowType => $purchaseFlowDef) {
62-
if ($flowType === $attributes['flow_type']) {
63-
$purchaseFlowDef->addMethodCall($methodName, [$id]);
64-
}
65-
}
61+
$attributes['id'] = $id;
62+
$attributes['index'] = ++$i;
63+
$attributes['priority'] = isset($attributes['priority']) ? $attributes['priority'] : 0;
64+
$allMethod[$attributes['flow_type']][] = $attributes;
65+
}
66+
}
67+
}
68+
/**
69+
* @var string $flowType
70+
* @var Definition $purchaseFlowDef
71+
*/
72+
foreach ($allMethod as $flowType => $flowMethod) {
73+
$purchaseFlowDef = isset($flowTypes[$flowType]) ? $flowTypes[$flowType] : null; ;
74+
if (!is_null($purchaseFlowDef) && count($flowMethod) > 0) {
75+
// flow_typeごとにソートをしてセットする
76+
uasort($flowMethod, static fn ($a, $b) => $b['priority'] <=> $a['priority'] ? : $a['index'] <=> $b['index']);
77+
foreach ($flowMethod as $attributes) {
78+
$purchaseFlowDef->addMethodCall($methodName, [$attributes['id']]);
6679
}
6780
}
6881
}

0 commit comments

Comments
 (0)