1

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

7ochem
  • 7,532
  • 14
  • 51
  • 80
minlare
  • 695
  • 2
  • 8
  • 20

2 Answers2

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
            }
        }
    }
}
Joel Davey
  • 680
  • 5
  • 14
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.

Khoa TruongDinh
  • 32,054
  • 11
  • 88
  • 155