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;
    }
}
3
  • Specify what code you have try? Nov 22, 2017 at 10:22
  • Hello @DhirenVasoya please check edited question
    – Moin Malek
    Nov 22, 2017 at 10:43
  • Also specify the code which you have done in di.xml and also specify the location of di.xml. Nov 22, 2017 at 10:57

1 Answer 1

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>
4
  • 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, 2018 at 10:44
  • after implementing this, run deploy command and caching command. Then check. Jul 23, 2018 at 10:49
  • It just started working suddenly. No idea, why. Anyway, thanks.
    – mighty_hk
    Jul 23, 2018 at 10:57
  • @DhirenVasoya, I followed the code which you suggested but it's not working. magento.stackexchange.com/questions/304907/… Feb 21, 2020 at 10:56

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.