Magento – magento 2 how to override select-shipping-method.js

checkoutknockoutjsmagento2requirejs

when trying to override select-shipping-method.js in my custom module then getting this errors

1 – Uncaught Error: Script error for: Xyz_Customcheckout/js/model/quote
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:166)
at HTMLScriptElement.onScriptError (require.js:1681)

2 – GET http://127.0.0.1/xyz/abc/pub/static/version1556282180/frontend/Xyz/theme/en_US/Xyz_Customcheckout/js/model/quote.js net::ERR_ABORTED 404 (Not Found)

requirejs –

var config = {
    map: {
        '*': {


          'Magento_Checkout/js/action/select-shipping-method': 'Xyz_Customcheckout/js/action/select-shipping-method'

        }
  }
};

select-shipping-method.js

define(
[
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/action/set-shipping-information'
],
function (quote, setShippingAction) {
    "use strict";

    return function (shippingMethod) {
        quote.shippingMethod(shippingMethod);
        // Update totals on summary
        setShippingAction([]);
    };
} 
);

Best Answer

app/code/SR/MagentoCommunity/view/frontend/requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/action/select-shipping-method': {
                'SR_MagentoCommunity/js/mixin/select-shipping-method-mixin': true
            }
        }
    }
};

app/code/SR/MagentoCommunity/view/frontend/web/js/mixin/select-shipping-method-mixin.js

define([
    'jquery'
], function ($) {
    'use strict';

    return function (target) {
        return function (shippingMethod) {
            // call original method
            target(shippingMethod);
        };
    }
});
Related Topic