I want to add a checkout step to the sylius checkout process. It's working in the sense that when I am at cart overview and click checkout my added step is shown. But when I click "Next" I am getting an error "Unable to generate a URL for the named route “sylius_order_index” as such route does not exist."
What I did so far (for now to avoid distraction I called my checkout step "test"):
winzou_state_machine:
sylius_order_checkout:
states:
test_selected: ~
transitions:
select_test:
from: [cart, test_selected, addressed, shipping_selected, shipping_skipped, payment_selected, payment_skipped]
to: test_selected
address:
from: [cart, test_selected, addressed, shipping_selected, shipping_skipped, payment_selected, payment_skipped]
to: addressed
select_shipping:
from: [addressed, test_selected, shipping_selected, payment_selected, payment_skipped]
to: shipping_selected
select_payment:
from: [payment_selected, test_selected, shipping_skipped, shipping_selected]
to: payment_selected
callbacks:
after:
sylius_process_cart:
on: ["select_shipping", "address", "select_payment", "skip_shipping", "skip_payment", "select_test"]
do: ["@sylius.order_processing.order_processor", "process"]
args: ["object"]
sylius_shop:
product_grid:
include_all_descendants: true
checkout_resolver:
route_map:
cart:
route: sylius_shop_checkout_test
test_selected:
route: sylius_shop_checkout_address
sylius_shop_checkout_start:
path: /
methods: [GET]
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: sylius_shop_checkout_test
sylius_shop_checkout_test:
path: /test
methods: [GET, PUT]
defaults:
_controller: sylius.controller.order:updateAction
_sylius:
event: test
flash: false
template: "Checkout/Test/test.html.twig"
form:
type: App\Form\TestType
repository:
method: findCartForAddressing
arguments:
- "expr:service('sylius.context.cart').getCart().getId()"
state_machine:
graph: sylius_order_checkout
transition: select_test
#after this all other states as they are in native Sylius in this file. The original checkout.yml is completely overridden with this one.
I followed the compiler in MY as opposed to NATIVE checkout steps and the difference is that in
$postEventResponse = $postEvent->getResponse();
if (null !== $postEventResponse) {
return $postEventResponse;
}
the Response object is null (thereby the if is not gotten into and the compiler moves on generating the arbirary/misleading error message mentioned above). So I noticed that occurs because in
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 where to add it. Can anybody point me to where/how that is done?
I solved it myself. Everything that was missing was the following in 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'