3

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.

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Dec 2, 2015 at 16:13

2 Answers 2

16

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.
 };
});
answered Dec 2, 2015 at 18:56
3
  • 2
    thanks Kandy, this is so cool, don't have an idea why it's still not in M2 docs Commented Apr 19, 2016 at 15:21
  • this method is call before right! can you tell me how to call after of parent method? Commented 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 Link Commented Nov 9, 2017 at 10:34
0

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
answered Feb 4, 2019 at 21:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.