cancel
Showing results for 
Search instead for 
Did you mean: 

Checkout - load javascript in specific step

Checkout - load javascript in specific step

Hello all together,

I've added a custom step in Magento Checkout. My target is to implement an API call to receive some information while checkout. Unfortunately I'm absolutely new to Knockout.js.

What I've done before:

  • Create a javascript file in app\design\frontend\[MyExtension]\[MyModule]\Magento_Checkout\web\js\custom.js
    define(['jquery'], function ($) {
        "use strict";
        return function test() {
            console.log("test");
        }
    });
  • Add my javascript file in requirejs-config.js
    map: {
            '*': {
                checkoutjs: 'Magento_Checkout/js/custom'
            }
        },
  • Call my custom javascript in onepage.phtml
    <script type="text/javascript">
    require(['jquery', 'checkoutjs'], function($, test) {
    test();
    });
    </script>

Everything is working fine. But my problem is, that the function is called within the first checkout step (Shipping address). So is it possible to load the javascript later in my custom second step? 

Or otherwise is it possible to find out the current step to add an event or something like that?