3

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);
        }
    });
});
  • 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 '18 at 19:11
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);
            }
        });
    });
| improve this answer | |
  • can you tell me this which js file path, thank you @bramulous – niceonelee Apr 28 '18 at 19:59
  • 2
    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 '18 at 15:51

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.