How do I execute a custom flow trigger from a plugin in Shopware >=6.5?

45 views Asked by At

Somehow/somewhere a flow trigger has to be executed, right? But I can't tell how. The docs are both lacking and outdated in that regard.

I got the trigger to show up in the Flow Builder, so I can assign an action for it, like adding a tag to an order. But if I then try to execute my event something like this somewhere in my plugin:

$this->eventDispatcher->dispatch(new OrderSentEvent($order, $context));

…the event dispatcher doesn't seem to know what to do with it because ${dispatcher}->hasListeners($eventName) comes up empty so it ends up in its orphanedEvents property. The event class is defined like this:

class OrderSentEvent extends Symfony\Contracts\EventDispatcher\Event implements Shopware\Core\Framework\Event\OrderAware{}

What am I missing? This is the outdated guide I followed: https://developer.shopware.com/docs/guides/plugins/plugins/framework/flow/add-flow-builder-trigger.html

There is no BusinessEventInterface anymore in v6.5, for example and I'm not sure what to make of that. I'm under the impression that if I'm just using the existing OrderAware, I don't have to create my own Storer, right?

1

There are 1 answers

0
gaxweb On
$this->eventDispatcher->dispatch(new OrderSentEvent($order, $context), 'name.goes.here');

…did the trick. No event subscriber could be found, because if you don't provide a name as 2nd argument, the full class name will be used, but the Flow Builder apparently uses the custom one.