0

I need to trigger the call that updates the shipping methods on the checkout page when the city, address lines, telephone and email fields change. Just like when the shipping methods are updated when the postcode, country and province fields change.

I have tried following the steps in this tutorial form the official docs (https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_carrier.html), but it seems this only validates the fields client-side and does not trigger the shipping methods update call?

  • Please on change the city, address lines, telephone and email fields change and any ajax request happen or not – Amit Bera Jun 5 at 10:43
  • @AmitBera - thank you for the response. At the moment no ajax calls are fired on change of the fields you mentioned. Only on change of postcode, province and country is an ajax call made for estimate-shipping-methods – Joe_Coder Jun 5 at 12:31
0

After so much investigation I found one solution. I have tried for Offline shipping methods as described follows and its working fine for me:

Namespace/Module/view/frontend/requirejs-config.js

var config = {
    "map": {
        "*": {
            "Magento_OfflineShipping/js/model/shipping-rates-validation-rules/flatrate": "Namespace_Module/js/model/shipping-rates-validation-rules/flatrate",
            "Magento_OfflineShipping/js/model/shipping-rates-validation-rules/freeshipping": "Namespace_Module/js/model/shipping-rates-validation-rules/freeshipping",
            "Magento_OfflineShipping/js/model/shipping-rates-validation-rules/tablerate": "Namespace_Module/js/model/shipping-rates-validation-rules/tablerate"
        }
    }
};

Namespace/Module/view/frontend/web/js/model/shipping-rates-validation-rules/flatrate.js

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

    return {
        /**
         * @return {Object}
         */
        getRules: function () {
            return {
                'country_id': {
                    'required': true
                },
                'city': {
                    'required': true
                },
                'telephone': {
                    'required': true
                }
            };
        }
    };
});

Namespace/Module/view/frontend/web/js/model/shipping-rates-validation-rules/freeshipping.js

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

    return {
        /**
         * @return {Object}
         */
        getRules: function () {
            return {
                'country_id': {
                    'required': true
                },
                'city': {
                    'required': true
                },
                'telephone': {
                    'required': true
                }
            };
        }
    };
});

Namespace/Module/view/frontend/web/js/model/shipping-rates-validation-rules/tablerate.js

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

    return {
        /**
         * @return {Object}
         */
        getRules: function () {
            return {
                'postcode': {
                    'required': true
                },
                'country_id': {
                    'required': true
                },
                'region_id': {
                    'required': true
                },
                'region_id_input': {
                    'required': true
                },
                'city': {
                    'required': true
                },
                'telephone': {
                    'required': true
                }
            };
        }
    };
});

These rules will automatically applied on change event of telephone and city fields.

Note: I have tried for Offline shipping methods only. If you wan to do it for other shipping methods, then you can try in the same way.

  • Thank you, @Dhara_Bhatti, this helped in the right direction! Got it working for all the fields I need except email. Any ideas how to listen for change on email field as well? – Joe_Coder Jun 9 at 15:11

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.