Magento 2 javascript plugin after method is executed in wrong time
If you look at target file Magento/Checkout/view/frontend/web/js/view/shipping.js
,you'll see that this is requirejs
module which returns UiComponent (child of Magento_Ui/js/form/form
).
In your example you have been used mage/utils/wrapper
but this util
applicable only for functions (like Magento/Checkout/view/frontend/web/js/action/create-billing-address.js
).
For extending UiComponent you need to use base method extend
:
var config = {
config: {
mixins: {
'Magento_Checkout/js/view/shipping': {
'Vendor_checkoutShipping/js/shipping-method-mixin': true
}
}
}};
shipping-method-mixin.js
define([], function () {
'use strict';
return function (Component) {
return Component.extend({
validateShippingInformation: function () {
var result = this._super();
result = this._modifyResult(result);
return result;
}
});
}
});
I'm not 100% sure, but I think mixins on ui components do not work as you are expecting it, since ui components return an ui component object which work slightly differtent, like further described here.
what you can do, is overriding the ui component (by creating the file in your theme like: app/design/Vendor/theme/Magento_Checkout/web/js/view/shipping.js
) in your theme and extend it from the original ui component:
/*global define*/
define(['Magento_Checkout/js/view/shipping'], function (Component) {
'use strict';
return Component.extend({
validateShippingInformation: function () {
var originalResult = this._super();
var newResult = this.doYourStuff(originalResult);
return newResult;
}
});
}
);
while you can of course add any object you need to the define function array