1

I'm facing a strange issue with Magento 2.2 I've 4 allowed countries on my store Shipping methods on checkout page are not displaying until user changes any country. Default country is set to United Arab Emirates, if any user from UAE tries to place an order he sees UAE as default selection .. so he does not change it which causes no Shipping Methods.

I'm thinking either I should not select UAE as default country, but how to do it?

or

How to refresh shipping methods block automatically?

You can visit the store yourself at: www.trydealz.com

2

It seems that if you add pincode shipping method get loaded as per Magento standard function. It is already working on your store.

But you need to load shipping method on city change or make zipcode mandatory

Update shipping on city field use below code

You need to add mixin for shipping-rates-validation-rules

Add mixins in your custom module requirejs-config.js

create file in custom module at app/code/Vendorname/ModuleName/view/frontend/requirejs-config.js add below code to it

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

Create shipping-rates-validation-rules-mixin.js at app/code/Vendorname/ModuleName/view/frontend/web/js/model/shipping-rates-validation-rules-mixin.js

add below code to it

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

    return function (targetFunction) {
        targetFunction.getObservableFields = function () {
            var self = this,
                observableFields = [];

            $.each(self.getRules(), function (carrier, fields) {
                $.each(fields, function (field) {
                    if (observableFields.indexOf(field) === -1) {
                        observableFields.push(field);
                    }
                });
            });

          observableFields.push('city');


            return observableFields;
        }

        return targetFunction;
    };
});

For more reference check this

1
  • thanks for your response .. I've tried above solution .. but it is not working ... also added registration.php and etc/module.xml but no success – Muhammad Shuja Apr 4 '19 at 19:38

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.