Search code examples
symfonysylius

How to customize checkout state machine in Sylius (e.g overriding configs in Symfony)


I need to customize the checkout process in Sylius Standard.

I follow the documentation here https://docs.sylius.com/en/1.12/cookbook/shop/checkout.html but it's outdated and not working on a fresh new project (acme demo project). I suppose that the documentation is not upated for Symfony 6.

I tried to override the checkout state machine:

  • By creating a new file in src/Resources/SyliusCoreBundle/config/app/state_machine/sylius_order_checkout.yml
  • By creation a new file in app/Resources/SyliusCoreBundle/config/app/state_machine/sylius_order_checkout.yml
  • By creating a new file in config/packages/sylius_order_checkout.yaml or with other names like config/packages/winzou_state_machine.yaml

The content is:

winzou_state_machine:
    sylius_order_checkout:
        class: "%sylius.model.order.class%"
        property_path: checkoutState
        graph: sylius_order_checkout
        state_machine_class: "%sylius.state_machine.class%"
        states:
            cart: ~
            addressed: ~
            payment_skipped: ~
            payment_selected: ~
            completed: ~
        transitions:
            address:
                from: [cart, addressed, payment_selected, payment_skipped]
                to: addressed
            skip_payment:
                from: [addressed]
                to: payment_skipped
            select_payment:
                from: [addressed, payment_selected]
                to: payment_selected
            complete:
                from: [payment_selected, payment_skipped]
                to: completed
        callbacks:
            after:
                sylius_process_cart:
                    on: ["address", "select_payment"]
                    do: ["@sylius.order_processing.order_processor", "process"]
                    args: ["object"]
                sylius_create_order:
                    on: ["complete"]
                    do: ["@sm.callback.cascade_transition", "apply"]
                    args: ["object", "event", "'create'", "'sylius_order'"]
                sylius_save_checkout_completion_date:
                    on: ["complete"]
                    do: ["object", "completeCheckout"]
                    args: ["object"]
                sylius_skip_shipping:
                    on: ["address"]
                    do: ["@sylius.state_resolver.order_checkout", "resolve"]
                    args: ["object"]
                    priority: 1
                sylius_skip_payment:
                    on: ["address"]
                    do: ["@sylius.state_resolver.order_checkout", "resolve"]
                    args: ["object"]
                    priority: 1

But when I clear the cache and debug with php bin/console debug:winzou:state-machine I get:

You have just selected: sylius_order_checkout
+--------------------+
| Configured States: |
+--------------------+
| cart               |
| addressed          |
| shipping_selected  |
| shipping_skipped   |
| payment_skipped    |
| payment_selected   |
| completed          |
+--------------------+

As you can see, shipping_selected and shipping_skipped are still listed... Why?

For information, it works if I do the same configuration directly inside the bundle configuration file \vendor\sylius\sylius\src\Sylius\Bundle\CoreBundle\Resources\config\app\state_machine\sylius_order_checkout.yml


Solution

  • I find a way to customize the checkout process only by using settings in admin backend:

    • disable shipping by product
    • using offline payment
    • enable skip payment if only one in channel settings
    • enable skip shipment if only one in channel settings

    Thank you for your previous answers