Magento – In Magento 2, Why it is not refreshing shipping methods after State field select

ajaxcheckoutmagento2onepage-checkoutshipping-methods

In Magento 2, after Country filed select then shipping methods refreshing automatically. But why it is not refreshing shipping methods after State field select and how to apply refresh to state field also.

<item name="country_id" xsi:type="array">
    <item name="sortOrder" xsi:type="string">115</item>
</item>




<item name="region_id" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Ui/js/form/element/region</item>
    <item name="config" xsi:type="array">
        <item name="template" xsi:type="string">ui/form/field</item>
        <item name="elementTmpl" xsi:type="string">ui/form/element/select</item>
        <item name="customEntry" xsi:type="string">shippingAddress.region</item>
    </item>
    <item name="validation" xsi:type="array">
        <item name="required-entry" xsi:type="boolean">true</item>
    </item>
    <!-- Value of region_id field is filtered by the value of county_id attribute -->
    <item name="filterBy" xsi:type="array">
        <item name="target" xsi:type="string"><![CDATA[${ $.provider }:${ $.parentScope }.country_id]]></item>
        <item name="field" xsi:type="string">country_id</item>
    </item>
</item>

Best Answer

https://alanstorm.com/refresh-shipping-rates-for-the-magento-2-checkout/

 requirejs([
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/shipping-rate-registry'
], function(quote, rateRegistry){


    var address = quote.shippingAddress();// use here uid or region

    address.trigger_reload = new Date().getTime();

    rateRegistry.set(address.getKey(), null);
    rateRegistry.set(address.getCacheKey(), null);

    quote.shippingAddress(address);// use here uid or region
});

spomething like this

Related Topic