0

I have added a custom field on checkout in shipping address section using below code.

etc/frontend/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\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="ProcessAddressConfiguration" type="Vendor\Module\Block\Checkout\PassportProcessor"/>
    </type>
</config>

Block/Checkout/PassportProcessor.php

<?php
namespace Vendor\Module\Block\Checkout;

class PassportProcessor
{
    public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout){

        $passport_no = 'passport_no';

        $newField = [
            'component' => 'Magento_Ui/js/form/element/abstract',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'customEntry' => null,
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/input',
                'tooltip' => [
                    'description' => 'description'
                ]
            ],
            'dataScope' => 'shippingAddress.custom_attributes.' . $passport_no,
            'label' => 'Passport Number',
            'provider' => 'checkoutProvider',
            'sortOrder' => 0,
            'validation' => [
                'required-entry' => true
            ],
            'options' => [],
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true
        ];

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

        return $jsLayout;
    }
}

Questions:

  • In which tables I should save it so that when I pull the order, passport_no should be available in shipping address section of that order?
  • How I can save passport_no in those tables from here?

I went through multiple posts but I do not see a complete list of steps which should be taken to achieve it.

amitshree
  • 7,006
  • 12
  • 63
  • 116
  • Hi did you find answer to this question also there is a similar question here https://stackoverflow.com/questions/51319902/magento-2-add-a-custom-input-field-on-chackout-forrm-and-save-it – PhantomS Jun 24 '19 at 04:35
  • Not yet. As an alternative I have saved custom fields in quote and order tables. – amitshree Jun 29 '19 at 03:02
  • Would you share the code how to save it in quote and order tables – PhantomS Jun 30 '19 at 04:16
  • Here is code written which explains how to update quote https://magento.stackexchange.com/a/177481/9169 – amitshree Jul 01 '19 at 08:53

0 Answers0