1

I cannot inject some javascript dependencies of magento in my main.js.

ex: 'Magento_Checkout/js/action/get-payment-information', 'Magento_Checkout/js/model/totals'

Uncaught TypeError: Cannot read property 'quoteData' of undefined at quote.js:13

Uncaught TypeError: Cannot read property 'storeCode' of undefined at url-builder.js:12

I see problem with window.checkoutConfig

Do you have an idea to fix that ?

define([
    "jquery",
    'Magento_Checkout/js/action/get-payment-information',
    'Magento_Checkout/js/model/totals'
],
function ($, getPaymentInformationAction, totals) {});
  • 1
    Did you manage to fix this? If yes, could you please provide the fix? – Condor Mar 27 '18 at 11:20
1

The issue is that both file don't have the correct information when the page is loaded, as this information is only available on the checkout page.

When i added in a JS file with your same code onto any page on the site, i get the same errors. When i add that same file into a template loaded on the checkout page, the errors goes away and i'm able to output the contents of both the getPaymentInformationAction and totals into the console.

define([
        "jquery",
        'Magento_Checkout/js/action/get-payment-information',
        'Magento_Checkout/js/model/totals'
    ],
    function ($, getPaymentInformationAction, totals) {
        console.log(getPaymentInformationAction);
        console.log(totals);
    });

enter image description here

Without a clear understanding of how and where you are trying to use this file, i can't say for sure how to implement these files correctly.

| improve this answer | |
  • Thanks, so, how add add javascript file with "define" only on the checkout page ? – Kévin Vuillemin Jan 23 '18 at 2:09
  • (I merged the file javascript when production is enabled) – Kévin Vuillemin Jan 23 '18 at 2:15
  • It depends on how you are trying to do this. Are you creating a theme or a module? For testing i just put a <script type="text/x-magento-init"> in the vendor/magento/module-checkout/view/frontend/templates/onepage.phtml file override. That is only called on checkout, so it works that way. But unfortunately there are so many ways to do this depending on what your end goal is. Let me know and i'm sure we can figure out a solution. – circlesix Jan 23 '18 at 3:04
  • 1
    I want call my function javascript only on checkout, so i think your solution is the best ? Thanks a lot. – Kévin Vuillemin Jan 23 '18 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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