0

I defined a table rates like that:

ESP,*,*,1.0000,0.0000
ESP,Ceuta,*,1.0000,15.0000
ESP,Ceuta,*,2.0000,20.0000
...

The functionality is working correctly. But I don't like the user experience on checkout, because the default country is Spain but nothing else is filled, so on the shipping methods displays no method. Then when the user fills the form, it finally displays a shipping method depends on what region/zip code especified.

I want, by default, display the 0€ shipping method, because it's selected Spain. Then if the user chooses Ceuta it will display the 15€.

Is it possible to do that?

PS: I tried to trigger the estimate-shipping-methods JS function, on the change event for country dropdown... but I did not know how to do it, and neither know if it would work.

Tried to do something like that:

require([
    'jquery',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/shipping-rate-registry',
    'Magento_Checkout/js/model/shipping-rate-processor/new-address'
], function($, quote, rateRegistry, newAddressProcessor) {
    var address = quote.shippingAddress();
    console.log('address', address);
    rateRegistry.set(address.getCacheKey(), null);
    newAddressProcessor.getRates(address);
});

1 Answer 1

3

I solved.

The problem was actually that by default, the country was US instead of ES. On the checkout form, the dropdown selects Spain but it's not saved yet.

For solving this, I had to change Tax configuration, and set default country spain.

Your Answer

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

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