2

I am using this one code but once i update shipping info not getting refreshed info they retrieve old info how can i achieve that?

require([
    'jquery',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/shipping-service',
    'Magento_Checkout/js/model/shipping-rate-registry',
    'Magento_Checkout/js/model/shipping-rate-processor/customer-address',
    'Magento_Checkout/js/model/shipping-rate-processor/new-address',
], function($, quote, shippingService, rateRegistry, customerAddressProcessor, newAddressProcessor) {
    $('#target').on('click', function(e) {
        var address = quote.shippingAddress();
        console.log(address);
        // clearing cached rates to retrieve new ones
        rateRegistry.set(address.getCacheKey(), null);

        console.log(quote.shippingAddress()); // but getting old one 
        var type = quote.shippingAddress().getType();
        if (type) {
            customerAddressProcessor.getRates(address);
        } else {
            newAddressProcessor.getRates(address);
        }
    });
});
1
  • How are you updating shipping info? If you're changing the form element value with jquery val() or something, you need to trigger change on the element for the shipping rates observer to pick up the updated values.
    – David Tay
    Sep 28, 2018 at 19:11

1 Answer 1

2

Try this:

require([
        'jquery',
        'Magento_Checkout/js/model/quote',
        'Magento_Checkout/js/model/shipping-service',
        'Magento_Checkout/js/model/shipping-rate-registry',
        'Magento_Checkout/js/model/shipping-rate-processor/customer-address',
        'Magento_Checkout/js/model/shipping-rate-processor/new-address',
    ], function($, quote, shippingService, rateRegistry, customerAddressProcessor, newAddressProcessor) {
        $('#target').on('click', function(e) {
            var address = quote.shippingAddress();
            console.log(address);

            // reload address information
            address.trigger_reload = new Date().getTime();

            // clearing cached rates to retrieve new ones
            rateRegistry.set(address.getCacheKey(), null);

            console.log(quote.shippingAddress()); // but getting old one 
            var type = quote.shippingAddress().getType();
            if (type) {
                customerAddressProcessor.getRates(address);
            } else {
                newAddressProcessor.getRates(address);
            }
        });
    });
4
  • can you tell me this which js file path, thank you @bramulous
    – niceonelee
    Apr 28, 2018 at 19:59
  • 3
    Am having this exception "Property \"TriggerReload\" does not have corresponding setter in class \"Magento\\Quote\\Api\\Data\\AddressInterface\"." once I imlement above "address.trigger_reload "
    – Elamurugan
    May 23, 2018 at 15:51
  • I have the same issue updated shipping address not showing on checkout. please help
    – Liz Eipe C
    Jun 7, 2022 at 21:27
  • I am trying to refresh the sidebar but not working . Any solutions?
    – Liz Eipe C
    Jun 13, 2022 at 13:16

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.