Extra checkout step: missing listener

Hi! This is my first post here, I hope you can help me. I am trying to add an extra checkout step to the checkout process. There are a lot of things to do for that I noticed so I did as far as I was able to “reverse engineer” what is already there, but there is so much now already I thought I can better describe the symptoms and ask what you think I missed instead of posting everything I did.

I am getting an error " Unable to generate a URL for the named route “sylius_order_index” as such route does not exist." which seems to be a misleading error message which occurs because when I am in/at my self-added step and hit the “Next step”-button (to go from my step to the next step which is the addressing) there is a response object missing from an event which causes the compiler to jump over this if (in Bundle/Controller/ResourceController.php line 311):

            $postEventResponse = $postEvent->getResponse();
            if (null !== $postEventResponse) {
                return $postEventResponse;
            }

(So instead of returning here, the compiler walks further and tries to find the url for a path that does not exist which produces that misleading error message I posted above) The response is null. So I noticed that occurs because in symfony/event-dispatcher/EventDispatcher.php line 72

        if ($listeners) {
            $this->callListeners($listeners, $eventName, $event);
        }

$listeners is an empty array in my case whereas with every other native sylius step there is at least 1 listener subscribed here. I just don’t know how to do that. Can anybody point me to where/how that is done?

What am I missing? Thank you in advance!

1 Like

Found the answer myself. Had to add the following to services.yaml:

app.request.matcher:
    class: Symfony\Component\HttpFoundation\RequestMatcher

sylius.listener.checkout_redirect:
    class: Sylius\Bundle\CoreBundle\Checkout\CheckoutRedirectListener
    tags:
        - { name: 'kernel.event_listener', event: 'sylius.order.post_address',  method: 'handleCheckoutRedirect'}
        - { name: 'kernel.event_listener', event: 'sylius.order.post_select_shipping',  method: 'handleCheckoutRedirect'}
        - { name: 'kernel.event_listener', event: 'sylius.order.post_payment',  method: 'handleCheckoutRedirect'}
        - { name: 'kernel.event_listener', event: 'sylius.order.post_test',  method: 'handleCheckoutRedirect'}
    arguments:
        - '@request_stack'
        - '@sylius.router.checkout_state'
        - '@app.request.matcher'

This is undocumented as far as I know, so wasn’t easy to find.