1

I have overridden the vendor/magento/module-checkout/Block/Cart/LayoutProcessor.php in my module and added below code to set the default value of postcode

 class LayoutProcessorPlugin
 {
    public function afterProcess(LayoutProcessor $subject, array $jsLayout)
    {
       $jsLayout['components']['block-summary']['children']['block-shipping']['children']['address-fieldsets']['children']['postcode']['value'] = '90091';
      return $jsLayout;
    }
 }

But somehow when visiting the cart page it is not filling the default value in the 'Zip/Postal' field. Can someone tell me how to achieve this? I guess some knockout js code overrides this value. I don't know where I need to set this.

0

Please check below answer it will help you to modify JSLAYOUT of checkout page.

then you can manage your changes and achieve the same that as you want.

Add validation of 30 alphabets allowed to new shipping address form field. Magento 2

Hope this will work for you.

Thank you, Nirav Patel

0

Finally, after debugging I found the solution

The default postcode can be set by overriding the TaxConfigProvider class. To set it you have to use after plugin.

Step 1: Define plugin in di.xml

    <?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\Tax\Model\TaxConfigProvider">
            <plugin disabled="false" name="My_Module_Plugin_Frontend_Magento_Tax_Model_TaxConfigProvider" sortOrder="10" type="My\Module\Plugin\Frontend\Magento\Tax\Model\TaxConfigProvider"/>
        </type>
    </config>

Step 2: Create a plugin class

<?php


namespace My\Module\Plugin\Frontend\Magento\Tax\Model;

use Magento\Framework\Stdlib\CookieManagerInterface;

class TaxConfigProvider
{

    /**
     * @var CookieManagerInterface
     */
    private $cookieManager;

    /**
     * TaxConfigProvider constructor.
     * @param CookieManagerInterface $cookieManager
     */
    public function __construct(
        CookieManagerInterface $cookieManager
    ) {
        $this->cookieManager = $cookieManager;
    }

    /**
     * @param \Magento\Tax\Model\TaxConfigProvider $subject
     * @param $result
     * @return mixed
     */
    public function afterGetConfig(
        \Magento\Tax\Model\TaxConfigProvider $subject,
        $result
    ) {
        $result['defaultPostcode'] = $this->cookieManager->getCookie('custom_pincode');
        return $result;
    }
}

After implementing this code go to Store –> Configuration –> General –> Country Options here you will find an option of “Zip/Postal Code is Optional for”. Remove the country for which you want to set default zip code from this list otherwise, it will be not filled up in frontend.

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.