1

How do I extend Magento_Checkout/js/checkout-data.js in a custom theme?

2 Answers 2

0

We can override the js via RequireJs, in your module:

app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            'Magento_Checkout/js/checkout-data':
            'Vendor_Module/js/checkout-data'
        }
    }
};

We can read more here.

2
  • 1
    That is not the answer the op asked how to extend not over ride it.
    – Joel Davey
    Commented Feb 19, 2019 at 11:33
  • @JoelDavey that's an old answer. We should try with mixins. Commented Feb 19, 2019 at 11:39
2

One way to extend it is like this

/*jshint browser:true jquery:true*/
/*global alert*/
define([
    'jquery',
    'Magento_Customer/js/customer-data'
], function ($, storage) {
    'use strict';


    return function (checkoutData) {

        var mixin = {

            myCustomFunction: function() {

            }

        };

        return $.extend(checkoutData, mixin);
    };
});

your require-config.js

var config = {
    'config': {
        'mixins': {
            'Magento_Checkout/js/checkout-data': {
                'Vendor_Module/js/view/checkout-data-mixin': true
            }
        }
    }
}

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.