1

I've created a component to pre populate checkout Shipping Address form after document is loaded.

I've enter the city,postcode and country on the front end and first name and last name within quote.shippingAddress() e.g

quote.shippingAddress().firstname = 'John';
quote.shippingAddress().lastname = 'Doe';

But it seen that it ins't populating the form itself but it's populating the object fine. look screen shoot attached the form. enter image description here

The object :

enter image description here

As you can see when I refresh the page the object get populated but the form on first name and last name is empty.

Does anyone know how can I achieve this?

Thanks.

  • Did you find any solution? – Umar Sep 24 '18 at 9:57
  • @Umar Not quite but made it work with simple javascript for loop value and trigger changes otherwise it wouldn't validate either.e.g document.getElementsByName(field)[0].value = val; $("input[name~='" + field + "']").trigger('change'); – Juliano Vargas Sep 24 '18 at 11:14
0

I hope you found your way out since 2018 but for the ones who can have this problem, there is an easy way to populate this form (PHP side). You can use plugin for \Magento\Checkout\Block\Checkout\LayoutProcessor. On a afterProcess method, you would set what ever fits your need. For example :

$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['prefix']['value'] = $prefix;

The function needs to return $jsLayout as the plugged one does.

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.