Question About Command and Condition Execution Order in Merchant Portal State Machine

bhupendra.doniwal
bhupendra.doniwal Posts: 60 🧑🏻‍🚀 - Cadet

Hi everyone,

I'm currently working on a state machine for the Merchant Portal in Spryker. I’ve defined a transition from state A to B, and in this transition, I’ve attached both a condition and a command.

After debugging the flow, I noticed that the command is being executed before the condition, which is problematic in my case. The reason is that the command is triggering OMS events, and I only want that to happen if the condition passes.

My question is:
Is there a way to enforce the state machine to evaluate the condition before executing the command?
Or is there an established best practice in Spryker to handle this kind of flow?

Any insights, suggestions, or workarounds would be really appreciated!

Thanks in advance!

Answers

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 97 🏛 - Council (mod)

    The normal workflow is:
    1) An OMS event is triggered

    2) If there is a command, the command is executed, and that command can set something up for the condition to verify

    3) The transition is executed. If there is a condition, then the condition is verified for the transition to happen
    This is the way it works, so you should adapt your logic to these steps.

    Why should the command trigger an OMS event? The command could just set some value so that the transition you want to happen be executed . Commands shouldn't trigger OMS events as It could create a recursion issue as commands are executed by events