In Magento 2 I try to track shipping method change in JS.
For exemple when pickup relay is selected I need to display a specific message on frontend.
Do you how can I do this ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this community1. Register mixin
app/code/Acme/StackExchange/view/frontend/requirejs-config.js
let config = {
config: {
mixins: {
'Magento_Checkout/js/action/select-shipping-method': {
'Acme_StackExchange/js/action/select-shipping-method-mixin': true
}
}
}
};
2. Create mixin
app/code/Acme/StackExchange/view/frontend/web/js/action/select-shipping-method-mixin.js
define([
'mage/utils/wrapper'
], function (wrapper) {
'use strict';
return function (selectShippingMethod) {
return wrapper.wrap(selectShippingMethod, function (_super, shippingMethod) {
if (shippingMethod) {
// your logic before shippingMethod set to quote
}
_super(shippingMethod);
if (shippingMethod) {
// your logic after shippingMethod set to quote
}
});
};
});