1

I had referred this link How to auto fill the shipping address field but this is throw an error This is required Field.

I have to Auto fill Address in Magento 2 Checkout. I have to fill the State and Zip code.

Can anyone have idea to fill it?

di.xml file in `app/code/Vendor/Module/etc/frontend`




<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="vendor_assign_default_value" type="Vendor\Module\Plugin\Checkout\Model\Checkout\LayoutProcessor" sortOrder="100"/>
    </type>

LayoutProcessor file in Vendor\Module\Plugin\Checkout\Model\Checkout

<?php

namespace Vendor\Module\Plugin\Checkout\Model\Checkout;

use Magento\Checkout\Block\Checkout\LayoutProcessor as MageLayoutProcessor;

class LayoutProcessor
{
    public function afterProcess(MageLayoutProcessor $subject, $jsLayout)
    {

        $jsLayout['components']['

checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['postcode']['value'] = '10012';



         return $jsLayout;
    }
}
  • Specify what code you have try? – Dhiren Vasoya Nov 22 '17 at 10:22
  • Hello @DhirenVasoya please check edited question – Moin Malek Nov 22 '17 at 10:43
  • Also specify the code which you have done in di.xml and also specify the location of di.xml. – Dhiren Vasoya Nov 22 '17 at 10:57
2

You need to move your di.xml file from :

app/code/Vendor/Module/etc/frontend/di.xml

To

app/code/Vendor/Module/etc/di.xml

With code.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="vendor_assign_default_value" type="Vendor\Module\Plugin\Checkout\Model\Checkout\LayoutProcessor" sortOrder="100"/>
    </type>
</config>
  • This is not working on Magento 2.2.x. It's giving error "This is a required field". Do you have any idea regarding this? – mighty_hk Jul 23 '18 at 10:44
  • after implementing this, run deploy command and caching command. Then check. – Dhiren Vasoya Jul 23 '18 at 10:49
  • It just started working suddenly. No idea, why. Anyway, thanks. – mighty_hk Jul 23 '18 at 10:57

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.