0

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

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.

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

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, privacy policy and cookie policy

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