How to extend JavaScript class/method of checkout model class in Magento 2
To extend JavaScript class/method of checkout model class in Magento 2, create requirejs-config.js in your module with
1 |
var config = { config: { mixins: { 'Magento_Checkout/js/model/step-navigator': { 'You_Module/js/step-navigator/pluggin': true } } } }; |
And a js/step-navigator/pluggin.js file with the following content:
1 |
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. }; }); |
Source (