Action executed upon entering a CheckoutStep

David Wischner
David Wischner Software Engineer Posts: 5 ✨ - Novice

I would like something to be prepared at checkout in my Spryker project. At first I thought about implementing this as CheckoutPaymentStepEnterPreCheckPlugin. Unfortunately, I have noticed that this plugin stack is executed every time ‘requireInput’ is queried, which is also called when e.g. generating breadcrumbs. This means that my plugin would be executed at every single step during the checkout again and again. Of course I could still do it and add some condition which prevents it from doing the same thing again and again but I don't really like that workaround.

Do you have any suggestions how to improve this? IMO it would be great to have something like a CheckoutPaymentStepEnterPlugin-stack which would be executed within \SprykerShop\Yves\CheckoutPage\Process\Steps\PaymentStep::execute (right after the PreCheckPlugin-stack) and similar for other steps. What do you think?

Best Answer

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 110 ⚖️ - Guardians (admin)
    Answer ✓

    In that case, if if want to execute the plugin just once, you could extend the quoteTransfer to set that flag and verify before executing the plugin. Otherwise you´d have to override the StepFactory to either add a fake step or override the ones you´d like to customize.

Answers

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 110 ⚖️ - Guardians (admin)

    Hi David!
    Would you like to prepare something before placing the order or before a certain checkout step?
    Before placing the order, you have the PreConditionCheckerInterface, src/Spryker/Zed/Checkout/Business/Workflow/CheckoutWorkflow.php, and would be execute just once before placing the order

  • David Wischner
    David Wischner Software Engineer Posts: 5 ✨ - Novice

    Hi Hidran,

    thanks for your response. In my case, I'd like to select the payment method (in the Quote) based on all other information I have at this point. A similar need will occur for the ShipmentStep as well. Therefore the CheckoutWorkflow unfortunately is too late.

  • Hidran Arias
    Hidran Arias Senior Technical Trainer Sprykee Posts: 110 ⚖️ - Guardians (admin)
    Answer ✓

    In that case, if if want to execute the plugin just once, you could extend the quoteTransfer to set that flag and verify before executing the plugin. Otherwise you´d have to override the StepFactory to either add a fake step or override the ones you´d like to customize.