Repository: shopware/shopware (PHP)

Issue:
Rule Builder current child action sequence is not updated
### Shopware Version

6.7.0.0-rc.4

### Affected area / extension

Platform(Default)

### Actual behaviour

When talking about Flow Builder. There are two action avenues. One with a rule, one without. 

In our test we add 2 actions that run one after the other (e.g. customer gets assigned a group AND a status)


**SCENARIO 1. When make this without a rule, just EVENT -> 2 actions** 

`src/Core/Content/Flow/Dispatching/FlowExecutor.php: 170`

In this scenario the sequences run in a loop:
```php
foreach ($flow->getSequences() as $sequence) {
     ....
     $this->executeSequence($sequence, $event);
}

public function executeSequence(?Sequence $sequence, StorableFlow $event): void
{
    ....
    $event->getFlowState()->currentSequence = $sequence;
   ....
}
```
**In the first scenario, the currentSequence is correct, they run one after the other in the foreach, the data gets passed down.**

**SCENARIO 2. We make it with a rule, EVENT -> RULE -> TRUE -> 2 actions***

The loop still runs the same way, but, because of how Rule stuff works, instead of 2 sequences it just has one sequence that is nested. Thats why we look at method that runs it:

`src/Core/Content/Flow/Dispatching/FlowExecutor.php: 125`
```php
public function executeAction(ActionSequence $sequence, StorableFlow $event): void
{
         ...
         $this->callHandle($sequence, $event); // calls the parent (first) sequence
        ...
        $event->getFlowState()->currentSequence = $sequence; // still the parent sequence

        /** @var ActionSequence $nextAction */
        $nextAction = $sequence->nextAction;
        if ($nextAction !== null) {
            $this->executeAction($nextAction, $event); // the 2nd sequence started, but never updated
        }
```

### Expected behaviour

Expected that the currentSequence is correctly updated for nested child actions (nextAction).

The problem is that whenever `$action->handleFlow($event);` logic part of an action is running , it only gets the StorableFlow, but never knows what sequence is running it. So `currentSequence` must be updated correctly.

**Expectations:**
That the following line is either moved higher in the `executeAction` method, above `callHandle()` call:
```php
$event->getFlowState()->currentSequence = $sequence; 
```

**OR**

it gets updated before the call is made:
```php
    $nextAction = $sequence->nextAction;
    if ($nextAction !== null) {
        $event->getFlowState()->currentSequence = $nextAction;
        $this->executeAction($nextAction, $event);
    }
```

### How to reproduce

You can use the provided postman collection for both good/bad scenarios.
Xdebug the following: `Content/Flow/Dispatching/Action/ChangeCustomerGroupAction.php: 44`

Monitor `$flow->getFlowState()->getSequenceId();`. In the first scenario, it will be different across runs. For the second scenario, between the sequence calls it will not change, but it should. 

----
You can manually set up the flow. 
Create a flow. Event -> On Customer Login -> rule (All Valid) -> Set customer group. And another action - set customer group.

[postman_collection.json](https://github.com/user-attachments/files/20504605/postman_collection.json)



### Definition of Done

- [ ] An automated test covers the fix.
- [ ] Integration/E2E testing in staging is done.
- [ ] Changelog markdown file created or updated in /changelog/_unreleased directory.
- [ ] Developer documentation written/updated.
- [ ] End user and/or developer documentation written or updated with clarification.
- [ ] Regression test created to ensure bug does not reappear, and automated regression tests pass.
- [ ] Code changes resolve the reported bug without introducing new issues.


Discussion: Hi @augsteyer, thanks for the detailed issue report. Could you please add a bit more context on the root issue, e.g. what problem you are trying to solve (either as an administration user or developer using our APIs). That would help us prioritize this issue accordingly and better understand the context of this issue 🙂 

I just tried to set up a flow like in your description with two actions behind a rule condition and both seem to be executed just fine 🤔.

Also the class you mentioned `FlowExecutor` is marked as `@internal` and is basically an implementation detail. Is it calling a flow action you added (e.g. as a plugin) in a wrong way?

Also feel free to go ahead and open a pull request if you already have a solution ready to fix it 🙂 
@MalteJanz Thank you for looking into it. In a nutshell what I want to do is **save the Sequence ID of a Flow Action** which is firing. This is to prevent an infinite loop (action triggers an event that triggers an action, and so on). In order to prevent the loop, I need to identify exactly the Action that already ran. The way to do it is to check the sequence ID of a running Action and save it.

**In the first setup**, I can do this. We got this Flow structure:
```
Flow
|
-> Action 1 (sequence id: X)
-> Action 2 (sequence id: Y)
```
**Second scenario:**
```
Flow
|
-> Rule -> True ->
                    |
                     -> Action 1 (sequence id: X)
                     -> Action 2 (sequence id: X) // oops?
```

As for opening a PR, I would do it, but I fear I have no clue how to run the necessary tests to make sure everything is as expected. Also, as mentioned earlier, I am between two solutions. Both would work, but I also understand that this code is ran by Shopware's paid tier (Rise, Evolve), and I have no access to that to test weather my changes would cause any unexpected breakages with the extra added Events, Rules & Actions 🤔  

For context, here is a custom Action code that I am running:
```php
public function handleFlow(StorableFlow $flow): void
{
       $sequenceId = $flow->getFlowState()->getSequenceId();
       // save it to storage
}
```



Fix (patch):
diff --git a/src/Core/Content/Flow/Dispatching/FlowExecutor.php b/src/Core/Content/Flow/Dispatching/FlowExecutor.php
index d1949ff1d48..a5594508c1f 100644
--- a/src/Core/Content/Flow/Dispatching/FlowExecutor.php
+++ b/src/Core/Content/Flow/Dispatching/FlowExecutor.php
@@ -124,8 +124,7 @@ public function executeSequence(?Sequence $sequence, StorableFlow $event): void
 
     public function executeAction(ActionSequence $sequence, StorableFlow $event): void
     {
-        $actionName = $sequence->action;
-        if (!$actionName) {
+        if (!$sequence->action) {
             return;
         }
 
@@ -134,6 +133,7 @@ public function executeAction(ActionSequence $sequence, StorableFlow $event): vo
         }
 
         $event->setConfig($sequence->config);
+        $event->getFlowState()->currentSequence = $sequence;
 
         $this->callHandle($sequence, $event);
 
@@ -141,13 +141,11 @@ public function executeAction(ActionSequence $sequence, StorableFlow $event): vo
             return;
         }
 
-        $event->getFlowState()->currentSequence = $sequence;
-
-        /** @var ActionSequence $nextAction */
-        $nextAction = $sequence->nextAction;
-        if ($nextAction !== null) {
-            $this->executeAction($nextAction, $event);
+        if (!$sequence->nextAction instanceof ActionSequence) {
+            return;
         }
+
+        $this->executeAction($sequence->nextAction, $event);
     }
 
     public function executeIf(IfSequence $sequence, StorableFlow $event): void