Following this post answer I have used mixins of shipping.js
file to change the result of validateShippingInformation
method. My requirers-config.js
file is:
var config = {
config: {
mixins: {
'Magento_Checkout/js/view/shipping': {
'Vendor_checkoutShipping/js/shipping-method-mixin': true
}
}
}};
and shipping-method-mixin.js
file:
define([
'jquery',
'mage/utils/wrapper',], function ($, wrapper) {
'use strict';
return function (shipping) {
var newMethod = wrapper.wrap(shipping.validateShippingInformation, function (originalFunction) {
var result = originalFunction();
return after(result);
});
console.log(newMethod);
shipping.validateShippingInformation = newMethod;
return shipping;
};});
Problem I have: The file is read by browser when page is loaded (identified by breakpoints) and right then executed. But the method in original file that i tray to extend by using after method is executed by button click in front-end (why is the file not running after
the original method is executed). I do not need the script I added to run when the page is loading(reloaded) and I do not want to override the original javaScript file.
I need to change validateShippingInformation
value before the method setShippingInformation
if
sentence is being executed. The if sentence in shipping.js file is:
if (this.validateShippingInformation()) {.(I need to allow or disallow this code to run based on my additional logic. How can i do it?).}