Hi,
Is it possible to make one page checkout with state machines? I managed to link address, shipping and payment, but can't skip summary page where user places order. Is it possible to go directly to thank you page after user populates all order data?
This is state machine I made with 2 steps, and I would like to skip 'complete' step:
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: ~
order_populated: ~
completed: ~
transitions:
order:
from: [cart]
to: order_populated
complete:
from: [order_populated]
to: completed
callbacks:
after:
sylius_process_cart:
on: ["order"]
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"]
In fact, you don't quite need the state machine in your case. I'd recommend implementing your custom CheckoutController and resolve everything there.
Or if you decide to keep state machine it should be enough to remove order_populated and make a transition directly from cart state to the completed state. Because if I understand you correctly, you just want to skip order_populated (so middle step, where one will confirm the data) rather than complete which will create an order from the cart.
@lchrusciel yes, but you will still need to confirm form to get redirected to thank you page, as complete step creates order, gives you token then redirects you to payment step and redirect back to thankyou
@pjedrzejewski what is your suggestion?
If I understand you correctly, you want to display an address step(maybe with some additional fields) and then go straight to the thankyou page. If so, you can use this POC:
# src/Sylius/Bundle/ShopBundle/Resources/config/routing/checkout.yml
sylius_shop_checkout_start:
path: /
methods: [GET]
defaults:
_controller: FrameworkBundle:Redirect:redirect
route: sylius_shop_checkout_address
sylius_shop_checkout_address:
path: /address
methods: [GET, PUT]
defaults:
_controller: sylius.controller.order:updateAction
_sylius:
event: address
flash: false
template: SyliusShopBundle:Checkout:address.html.twig
form:
type: Sylius\Bundle\CoreBundle\Form\Type\Checkout\AddressType
options:
customer: expr:service('sylius.context.customer').getCustomer()
repository:
method: findCartForAddressing
arguments:
- "expr:service('sylius.context.cart').getCart().getId()"
state_machine:
graph: sylius_order_checkout
transition: address
redirect: # this section is new
route: sylius_shop_order_pay
parameters:
tokenValue: resource.tokenValue
# src/Sylius/Bundle/CoreBundle/Resources/config/app/state_machine/sylius_order_checkout.yml
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: ~
completed: ~
transitions:
address:
from: [cart]
to: completed
callbacks:
after:
sylius_process_cart:
on: ["address"]
do: ["@sylius.order_processing.order_processor", "process"]
args: ["object"]
sylius_create_order:
on: ["address"]
do: ["@sm.callback.cascade_transition", "apply"]
args: ["object", "event", "'create'", "'sylius_order'"]
sylius_save_checkout_completion_date:
on: ["address"]
do: ["object", "completeCheckout"]
args: ["object"]
# src/Sylius/Bundle/ShopBundle/Resources/config/app/config.yml
(...)
sylius_shop:
checkout_resolver:
pattern: /checkout/.+
route_map:
cart:
route: sylius_shop_checkout_complete
(...)
Of course, it doesn't solve all problems and I didn't add any shipping or payment related fields, but it works.
Can we close this one? Anyway, this one could be moved to SO /cc @paullla @antonioperic @pjedrzejewski @michalmarcinkowski
Yes, we used custom OrderController, and it worked great. Thank you.
Most helpful comment
Yes, we used custom OrderController, and it worked great. Thank you.