1

I want to call "estimate-shipping-methods" api on street field input change as it is called when the input of postcode, country field.

1

Add a mixin for shipping rates validation rules:

app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/model/shipping-rates-validation-rules': {
                'Vendor_Module/js/checkout/model/shipping-rates-validation-rules-mixin': true
            }
        }
    }
};

app/code/Vendor/Module/view/frontend/web/js/checkout/model/shipping-rates-validation-rules-mixin.js

In mixin we will wrap the original rules and add the street:

define([
    'jquery',
    'mage/utils/wrapper'
],function ($, Wrapper) {
    "use strict";

    return function (origRules) {
        origRules.getObservableFields = Wrapper.wrap(
            origRules.getObservableFields,
            function (originalAction) {
                var fields = originalAction();
                fields.push('street');

                return fields;
            }
        );
        
        return origRules;
    };
});

This will add the street rule to each available shipping method on the frontend.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.