[PW-5810] Enforce correct states when multiple states are assigned to a status #1397
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses the issue from #1173.
When configuring statuses, a status can be assigned to multiple states.
E.g. the status 'Waiting for capture' can be assigned to both the 'pending_payment' and 'processing' state. When configuring "Order status: payment authorisation" it is possible to select statuses that lead to the 'processing' state, thus 'Waiting for capture' is shown in the dropdown. When this status is selected it is possible for the flow to enter the 'pending_payment' state. This should not be possible.
Further explanation of the problem and the corresponding code can be found in #1173. This PR proposes a solution in which the possible states are passed as a parameter when the
setState
function is called in the Webhook module. Before selecting a state to enter, the list of possible states will be filtered on this parameter.E.g. this will prevent the 'pending_payment' state from the example to be removed.
When multiple states are possible to enter, and the passed status is also tied to all of these states (e.g. if 'Waiting for capture' would be assigned to both 'new' and 'processing' on "Order status: payment authorisation"). The first one that fits will be selected. This means the unpredictability is not fully removed, however this should be clear to the user as the 'Waiting for capture' label will appear multiple times in the dropdown.
Tested scenarios
Fixed issue:
Fixes #1173