0

Is there any way we can get the Selected shipping address object from Magento 2 Shipments page? Was trying to search for it like an observer but getting solutions only when you are on checkout.

1 Answer 1

0

Try This

Override the core file in your custom module Vendor/Modulename

Namespace/ModuleName/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            
            'Magento_Checkout/js/model/shipping-service' : 
            'NameSpace_ModuleName/js/model/shipping-service'      
        }
  }
};

Namespace/ModuleName/view/frontend/web/js/model/shipping-service.js

/*global define, url*/
define(
[
    'jquery', // For jQuery Added
    'Magento_Checkout/js/model/quote', // For Quote Added
    'ko',
    'Magento_Checkout/js/model/checkout-data-resolver'
],
function ($, quote, ko, checkoutDataResolver) {
    "use strict";
    var shippingRates = ko.observableArray([]);
    return {
        isLoading: ko.observable(false),
        /**
         * Set shipping rates
         *
         * @param ratesData
         */
        setShippingRates: function (ratesData) {
            if (loggedinCustomer == 1) {

                // you can get address of current shipping address here
                var address = quote.shippingAddress();

                   
                // STOP TO REMOVE ERROR MESSAGE FOR DHL IF SG

                shippingRates(ratesData);
                shippingRates.valueHasMutated();
                checkoutDataResolver.resolveShippingRates(ratesData);
            }
        },

        /**
         * Get shipping rates
         *
         * @returns {*}
         */
        getShippingRates: function () {
            return shippingRates;
        }
    };
  }
);

This Line : var address = quote.shippingAddress();

After that run upgrade,compile, deploy commands

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.