Basically I need to some method overwrite/extend of following Js class.
magento/module-checkout/view/frontend/web/js/model/step-navigator.js
Overwrite of this class through requirejs working fine. But I need to extend one of method of this class. here is an example of overwrite requirejs-config.js
var config = {
"map": {
"*": {
"Magento_Checkout/js/model/step-navigator": "SR_Checkout/js/model/step-navigator"
}
}
};
How to extend some method of any model class in checkout.
2 Answers 2
You need create requirejs-config.js in you module with
var config = {
config: {
mixins: {
'Magento_Checkout/js/model/step-navigator': {
'You_Module/js/step-navigator/pluggin': true
}
}
}
};
And js/step-navigator/pluggin.js file with content like
define(function () {
'use strict';
return function (target) { // target == Result that 'Magento_Checkout/js/model/step-navigator' returns.
// modify target
var navigateTo = target.navigateTo;
target.navigateTo = function(code, scrollToElementId) {
if (code == ...) { // before method
....
}
var result = navigateTo.apply(this, arguments);
//after method call
return result;
};
return target.
};
});
-
2thanks Kandy, this is so cool, don't have an idea why it's still not in M2 docsEugen Bogdanovich– Eugen Bogdanovich2016年04月19日 15:21:58 +00:00Commented Apr 19, 2016 at 15:21
-
this method is call before right! can you tell me how to call after of parent method?Chirag Prajapati– Chirag Prajapati2017年02月02日 05:26:37 +00:00Commented Feb 2, 2017 at 5:26
-
This is almost 2 years old now, just a FYI for anyone who comes across this in the future: Magento Mixin Docs LinkMackieeE– MackieeE2017年11月09日 10:34:24 +00:00Commented Nov 9, 2017 at 10:34
This still works in 2.2.7. Thank you very much KAndy. You can also add veriables if you want to change it like this:
var result = navigateTo.apply(this, [code, scrollToElementId]);
//after method call