1

I'm making a custom shipping module. When a user selects the shipping method, I want it to populate the shipping address fields with some custom address data.

I have overridden the select shipping method handler like so:

var config = {
    map: {
        '*': {
            'Magento_Checkout/js/action/select-shipping-method': 
'Vendor_Module/js/action/select-shipping-method'
        }
    }
};

I want to programatically set the form field values on the checkout page. Something like:

define([
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/action/select-shipping-address'
], function (quote, shipping) {
    'use strict';

    return function (shippingMethod) {
        shipping.street("99 Road Street");
        shipping.city("New York");
    };
});

Is there a way to do this without just dumping in the values using jquery?

3

1 Answer 1

0

Add parameters into object in this file "new-customer-address.js" is setting up the shipping address. find file in Magento_Checkout/js/model/ code library.

just add the values into these parameters

email: shipping_address.email, countryId: countryId, regionId: regionId || shipping_address.regionId, regionCode: shipping_address.region ? shipping_address.region['region_code'] : null, region: shipping_address.region ? shipping_address.region.region : null, customerId: shipping_address['customer_id'] || shipping_address.customerId, street: shipping_address.street ? _.compact(shipping_address.street) : shipping_address.street, company: shipping_address.company, telephone: shipping_address.telephone, fax: shipping_address.fax, postcode: shipping_address.postcode ? shipping_address.postcode : DefaultPostCodeResolver.resolve(), city: shipping_address.city, firstname: shipping_address.firstname, lastname: shipping_address.lastname, middlename: shipping_address.middlename, prefix: shipping_address.prefix, suffix: shipping_address.suffix, vatId: shipping_address['vat_id'], saveInAddressBook: shipping_address['save_in_address_book'], customAttributes: shipping_address['custom_attributes']

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.