How do I extend Magento_Checkout/js/checkout-data.js in a custom theme?
Asked
Active
Viewed 1,988 times
1
2 Answers
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
-
1That is not the answer the op asked how to extend not over ride it. – Joel Davey Feb 19 '19 at 11:33
-
@JoelDavey that's an old answer. We should try with mixins. – Khoa TruongDinh Feb 19 '19 at 11:39