Trying to activate EventSubscriber with state machine

Created on 28 February 2023, over 1 year ago
Updated 13 July 2023, over 1 year ago

Problem/Motivation

Hello! Im doing a project where you can buy (for free now) courses and get associated with a Moodle page, im using the .pre/post transition to get the user involved, to associate the person with moodle i use custom code that extends from Moodle Rest module (pretty good module if u are doing something similar with moodle), is an eventSubscriber that reacts on " fulfill.pre_transition " , just trying to use the state machine: trigger entity state transition to just activate the event and skip the part of commerce where you have to confirm the order (because is going to be free and not free products there, so, for free products im trying to just go direct to the eventSubscriber), if there is another way to activate that event passing the fields of the order im all hears

Steps to reproduce

in ECA im using bpmn.io so
1° Create a start event that reacts on State machine: Pre_transition
2° A connector to a Task with template on "State Machine: Workflowtransition" : "Fulfillment: Place Order"
3° Create an Entity: Load Task with token name "price", load entity from "Current Scope", type of entity "Order"
4° Another connector to a Task with template on "Entity: compare field value" name of the field to compare "total_price:number" equal to "0.000000" and entity "price"
5° and here is where i get lost a bit, i create a new Task with "Token: Set Value", token name "price.state", value to change "Completed", here i change the state of the product to completed but doesn't activates the eventSubscriber i created

So here all works, when a product total is 0.000000 (free) i can change the state of the order and show a message with the fields to see if its changed, but i cant get how to trigger the event

Thanx for the time to read this,
Hope i said it all right, i work in spanish cause the place where i work, so ignore the names in the ECA haha

💬 Support request
Status

Fixed

Version

1.0

Component

Documentation

Created by

🇦🇷Argentina renzocarletti

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @renzocarletti
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks @RenzoCarletti for posting your support request. It's difficult to work on this, as my Spanish is simply non-existant ;-) So, when you upload a model for review, it would be much better to keep names and comments in such a model in English - otherwise helping is not really possible.

    Not sure, what you want to achieve with your event subscriber. ECA is not designed to dispatch events from any custom code. If ECA functionality is not sufficient and you need something extra, you may want to write an action plugin. Such action plugins can then be called from within an ECA model.

  • 🇦🇷Argentina renzocarletti

    thanks for the fast answer Jurgen, well, changing the model to english and my request, i created an action, how can i send the "order" entity there? i need to work with the entity order from the commerce part (attached in a .txt what I have achieved) but im just getting the field like string, if the question is not easy to understand ill try to explain better, but in short, i need to send from eca the entity loaded on a field, to a custom module, using an Action, sorry if im not being good explaining ill try different redact if is not understandable, and if the request is not supposed to be made here, I will make it in another forum, thanks anyway

  • 🇩🇪Germany jurgenhaas Gottmadingen

    You can make your action entity aware by defining an entity context in the annotation. And in addition, you can make your action configurable so that you get config fields in ECA to define potentially other values as well that the action will then receive in its configuration and continue working with them.

    The best way to find out about the details is to review existing action, e.g. in the eca_content sub-module, which works a lot with entities that are forwarded to the actions.

    However, as ECA is able to work with entities, fields, tokens, states and so much more, it is very likely that you can achieve what you want without the need for custom code. Only if there is something missing, then you need your own plugins.

    I can't justify which way you needed to go. The description of the use case is very complex and hard to understand without the background. Instead of writing long paragraphs, it may be easier to structure the description in small items, just like you would probably do when writing a PHP program. And guess what, my own experience has been, when writing it down in such a structured way, it turns into a blue print on how I could do it in ECA.

    Maybe you want to give that approach a try. Should you get lost in the process, of course let us know and we try what we can to help.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Status changed to Fixed over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024