0

I want to call a particular third party js function in my custom js file.

XXX/YYY/view/frontend/web/js/view/payment/method-renderer/cashondelivery-method.js.

define([
        'Magento_Checkout/js/view/payment/default'
    ], function (Component) {
        'use strict';

    return Component.extend({
        defaults: {
            template: 'XXX_YYY/payment/cashondelivery'
        },

        /**
         * Returns payment method instructions.
         *
         * @return {*}
         */
        getInstructions: function () {
            //some code here
        },
        getCodFeeInstruction: function () {
            return window.checkoutConfig.codfee_msg;
        }
    });
});

I need to call getInstructions() in my custom js file.

In my custom file:

AAA/ZZZ/js/view/payment/method-renderer/online-method.js

define([
    'jquery',
    'Magento_Checkout/js/view/payment/default',
    'mage/url',
    'XXX_YYY/js/view/payment/method-renderer/cashondelivery-method'
], function ($, Component, url, payment) {
    'use strict';
    console.log('online');
    return Component.extend({
        defaults: {
            template: 'AAA_ZZZ/payment-methods/onlinepayment',

        },       

        getPreparePayment: function () {
            console.log("asd");
            payment.getInstructions();
        }
    });
});

But it returns payment.getInstructions is not a function error in console.

How to do that.

Thanks.

0

Just create or edit requirejs-config.js file from below path.

/app/code/AAA/ZZZ/view/frontend/requirejs-config.js

And place below code in requirejs-config.js

var config = {
map: {
    '*': {
      'payment': 
          'XXX/YYY/view/frontend/web/js/view/payment/method-renderer/cashondelivery-method'
    }
   }
};

Define this js in your custom file as :

define([
'jquery',
'Magento_Checkout/js/view/payment/default',
'mage/url',
'payment'
]
  • Not working .... Its repeat same error – Mahi M Aug 19 '19 at 8:47
  • Delete static content and deploy static content. – Mitro Aug 19 '19 at 9:47
  • Check your js is loading in requirejs in browser – Mitro Aug 19 '19 at 9:47

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.