0

When I visit the checkout page, the checkout summary loads after my custom.js file. This means when i'm trying to pull values from the summary to perform some logic on these values always return null.

Is there any way of me setting my custom.js file as the last file that gets loaded?

1 Answer 1

3
  1. app/design/frontend/Vendor/theme-name/Magento_Checkout/web/js/custom.js

    your js functions goes here exemple :

    define(['jquery'], function($){
        "use strict";
        return function hello()
        {
            alert('Bonjour Amir');
        }
    });
    
  2. app/design/frontend/Vendor/theme-name/requirejs-config.js

    var config = {
        map: {
            '*': {
                checkoutjs: 'Magento_Checkout/js/custom'
            }
        }
    
    };
    
  3. app/design/frontend/Vendor/theme-name/Magento_Checkout/templates/onepage.phtml

    Here we call our js function otherwise, the js will not be loaded !

    <script type="text/javascript">
        require(['jquery', 'checkoutjs'], function($, hello) {
            hello();
        });
    </script>
    
    • Clean all this folder contents pub/static except .htaccess
    • Clean all this folder contents var/view_preprocessed
    • Clean all this folder contents var/cache
    • Deploy the static-content: php bin/magento setup:static-content:deploy -f
8
  • Thanks for the fast response. Where about's do I put the code for onepage.phtml? Theres already quite a bit of stuff in that file. Also, where does requirejs-config.js go? Will this just sit as the top level outside of the Magento modules? Commented Jan 16, 2019 at 9:35
  • you can try below file app/design/frontend/Vendor/theme-name/Magento_Checkout/templates/onepage.phtml or create custom js like above step Commented Jan 16, 2019 at 9:38
  • Sorry, what I meant was. Where abouts do I place the code-block within onepage.phtml? There are other scripts in there already. I presume by just placing it amongst the other script tags this will work. Also for the requirejs-config.js does this file already exist or is this an additional file I have to create myself? Thanks again Commented Jan 16, 2019 at 9:50
  • you can create new script in end of onepage.phtml file <script type="text/javascript"> require(['jquery', 'checkoutjs'], function($, hello) { hello(); }); </script> Commented Jan 16, 2019 at 9:54
  • requirejs-config.js not create additional file you can add in existing file Commented Jan 16, 2019 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.