1

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>
5
  • this is default, if it is not refreshing go to browser console to check for any errors or to web-server logs , can`t say more. May 7, 2019 at 6:59
  • thanks, but how to apply refresh to state field? May 7, 2019 at 7:09
  • her you can read how to create new one for testing , or find where you can check it May 7, 2019 at 7:14
  • I need in checkout page shipping methods refresh after selecting State field also May 7, 2019 at 7:19

1 Answer 1

0

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

2
  • Alexey, is there no Magento setting to control refreshing of shipping section? Feb 24, 2023 at 13:17
  • Hi, they aren't needed, but you can use the saveShippingInformation() call, which must be triggered when you select a shipping method at the checkout. But it depends on your needs, 99% of the default changes - could be resolved by plugins/observers without "big changes" at the JS/ frontend level. Try to create a new question here and I think that you'll get lots of the answers :) Mar 12, 2023 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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