#StackBounty: #magento2 #customer-attribute #extension-attributes How to pass a attribute code dynamically in extension_attributes.xml

Bounty: 50

How to pass a attribute code dynamically in extension_attributes.xml
or how to save a custom field value in db in checkout page without extension_attributes

extension_attributes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="MagentoQuoteApiDataAddressInterface">
        <attribute code="How_to_pass_code_dynamically_here" type="string" />
        <attribute code="How_to_pass_code_dynamically_here" type="string" />
    </extension_attributes>
</config>

It should contain getters and setters of address attribute. In this case. <attribute_code="example"> setExample(), getExample()

attribute_code are given by admin dynamically in backend

code:

 $attributeCollection = $this->helper->getUserDefinedAttribures();
       if ($attributeCollection->getSize() > 0) 
       {
         foreach ($attributeCollection as $attribute)    
         {
          if ($this->helper->isAttribureForCheckoutRegister($attribute- 
          >getAttributeCode()))
         {

           $customAttributeCode = $attribute->getAttributeCode();
            var_dump($customAttributeCode);

          }
        }
    }

image:

enter image description here

I have created a customer attribute which created dynamically from backend its fine works in customer_account_create and customer_account_edit and I stuck at saving customer attribute field data in after saving address information in the checkout form. After filling shipping address, shipping and press next button method I m getting the following error

message: “Internal Error. Details are available in Magento log file. Report ID: webapi-5d3aa1ebbf82a”

Exception log: ‘Report ID: webapi-5d3aa1ebbf82a; Message: Property “TestAge” does not have corresponding setter in class “MagentoQuoteApiDataAddressExtensionInterface”.’ in D:wamp64wwwm2magentovendormagentoframeworkWebapiErrorProcessor

and I followed this link

app/code/Cm/CustomerAttribute/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="MagentoCheckoutBlockOnepage">
        <arguments>
            <argument name="layoutProcessors" xsi:type="array">
                <item name="cm__fields_layoutprocessor" xsi:type="object">CmCustomerAttributeBlockCheckoutLayoutProcessor</item>
            </argument>
        </arguments>
    </type>
</config>

app/code/ Cm/CustomerAttribute/Block/Checkout/LayoutProcessor.php

<?php
namespace CmCustomerAttributeBlockCheckout;

class LayoutProcessor
{
    protected $customerSession;
    protected $resultPageFactory;
    public function __construct(CmCustomerAttributeHelperCustomerattribute $helper,
    MagentoCustomerApiCustomerRepositoryInterface $customerRepositoryInterface,
    MagentoCustomerModelSession $customerSession)
    {
        $this->helper = $helper;
        $this->customerRepositoryInterface = $customerRepositoryInterface;
        $this->customerSession = $customerSession;
    }
    public function afterProcess(
        MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
        $jsLayout
    ) {
        $attributeCollection = $this->helper->getUserDefinedAttribures();

       if ($attributeCollection->getSize() > 0) 
       {
         foreach ($attributeCollection as $attribute)

         {
        if ($this->helper->isAttribureForCheckoutRegister($attribute->getAttributeCode()))
        {
        $frontEndLabel = $attribute->getStoreLabel($this->helper->getStoreId());

        $customAttributeCode = $attribute->getAttributeCode();
      if($this->customerSession->isLoggedIn()) {

        $customerId =$this->customerSession->getCustomer()->getId();
         $customer =$this->customerRepositoryInterface->getById($customerId);
        $customerAttr = $customer->getCustomAttribute($customAttributeCode)->getValue();
        }
        else
        {
          $customerAttr = NULL;
        }
        $fieldRequiredClass = ($attribute->getIsRequired()) ? 'true' : '' ;
        if($fieldRequiredClass == '')
        {
            $fieldRequiredClass = false;
        }
        $fieldFrontendClass = ($attribute->getFrontendClass()) ? $attribute->getFrontendClass() : '';
        $fieldInput =$attribute->getFrontendInput();
        $attributeId = $attribute->getAttributeId();
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();

        $attributeOptionAll = $objectManager->create(MagentoEavModelResourceModelEntityAttributeOptionCollection::class)
                                    ->setPositionOrder('asc')
                                    ->setAttributeFilter($attributeId)
                                    ->setStoreFilter()
                                    ->load();
        $opt_val = array();
        $allOptions=array();


        foreach ($attributeOptionAll->getData() as $key => $v) 
        {
          // $allid = $v['attribute_id'];
          $opt_val['value'] = $v['option_id'];
          $opt_val['label'] = $v['value'];
          $allOptions[] = $opt_val;
      }
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$customAttributeCode] = $this->addNewField($customAttributeCode,$frontEndLabel, $fieldRequiredClass,  $fieldFrontendClass,$fieldInput,  $allOptions, $customerAttr );

        }
      }
    }
    return $jsLayout;
    }

    private function addNewField($customAttributeCode, $frontEndLabel, $fieldRequiredClass,  $fieldFrontendClass, $fieldInput, $allOptions, $customerAttr  )
    {
        if($fieldInput == 'text')
        {
            $fieldInputType = 'input';
            $fieldAbstract =  'abstract';
        }
        elseif ($fieldInput == 'date') {
           $fieldInputType = 'date'; 
           $fieldAbstract =  'date';
        }
        elseif ($fieldInput == 'select') {
           $fieldInputType = 'select'; 
           $fieldAbstract =  'select';
        }

        elseif ($fieldInput == 'boolean') {
           $fieldInputType = 'select'; 
           $fieldAbstract =  'select';
           $allOptions = [
                 ['value' => '0', 'label' => 'No'],
                 ['value' => '1', 'label' => 'Yes']
               ];

        }
         elseif ($fieldInput == 'textarea') {
           $fieldInputType = 'textarea'; 
           $fieldAbstract =  'textarea';

        }
        $customField = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'customEntry' => null,
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'rows' => 5
                // 'tooltip' => [
                //     'description' => 'this is what the field is for',
                // ],
            ],
            'dataScope' => 'shippingAddress.custom_attributes' . '.' . $customAttributeCode,
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'sortOrder' => 1000,
            'validation' => [$fieldFrontendClass => true , 
                'required-entry' => $fieldRequiredClass],
            'options' =>  $allOptions,
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true,
            'value' => $customerAttr
        ];

         return $customField;
    }
}

app/code/Cm/CustomerAttribute/view/frontend/requirejs-config.js

 var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/action/set-billing-address': {
                'Cm_CustomerAttribute/js/action/set-billing-address-mixin': true
            },
            'Magento_Checkout/js/action/set-shipping-information': {
                'Cm_CustomerAttribute/js/action/set-shipping-information-mixin': true
            },
            'Magento_Checkout/js/action/create-shipping-address': {
                'Cm_CustomerAttribute/js/action/create-shipping-address-mixin': true
            },
            'Magento_Checkout/js/action/place-order': {
                'Cm_CustomerAttribute/js/action/set-billing-address-mixin': true
            },
            'Magento_Checkout/js/action/create-billing-address': {
                'Cm_CustomerAttribute/js/action/set-billing-address-mixin': true
            }
        }
    }
};

app/code/Cm/CustomerAttribute/view/frontend/web/js/action/create-shipping-address-mixin.js

define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_Checkout/js/model/quote'
], function ($, wrapper,quote) {
    'use strict';

    return function (setShippingInformationAction) {
        return wrapper.wrap(setShippingInformationAction, function (originalAction, messageContainer) {

            if (messageContainer.custom_attributes != undefined) {
                $.each(messageContainer.custom_attributes , function( key, value ) {
                    messageContainer['custom_attributes'][key] = {'attribute_code':key,'value':value};
                });
            }

            return originalAction(messageContainer);
        });
    };
});

app/code/Cm/CustomerAttribute/view/frontend/web/js/action/set-billing-address-mixin.js

define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_Checkout/js/model/quote'
], function ($, wrapper,quote) {
    'use strict';

    return function (setBillingAddressAction) {
        return wrapper.wrap(setBillingAddressAction, function (originalAction, messageContainer) {

            var billingAddress = quote.billingAddress();

            if(billingAddress != undefined) {

                if (billingAddress['extension_attributes'] === undefined) {
                    billingAddress['extension_attributes'] = {};
                }

                if (billingAddress.customAttributes != undefined) {
                    $.each(billingAddress.customAttributes, function (key, value) {

                        if($.isPlainObject(value)){
                            value = value['value'];
                        }

                        billingAddress['extension_attributes'][key] = value;
                    });
                }

            }

            return originalAction(messageContainer);
        });
    };
});

app/code/Cm/CustomerAttribute/view/frontend/web/js/action/set-shipping-information-mixin.js

define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_Checkout/js/model/quote'
], function ($, wrapper,quote) {
    'use strict';

    return function (setShippingInformationAction) {
        return wrapper.wrap(setShippingInformationAction, function (originalAction, messageContainer) {

            var shippingAddress = quote.shippingAddress();

            if (shippingAddress['extension_attributes'] === undefined) {
                shippingAddress['extension_attributes'] = {};
            }

            if (shippingAddress.customAttributes != undefined) {
                $.each(shippingAddress.customAttributes , function( key, value ) {

                    if($.isPlainObject(value)){
                        value = value['value'];
                    }

                    shippingAddress['customAttributes'][key] = value;
                    shippingAddress['extension_attributes'][key] = value;

                });
            }

            return originalAction(messageContainer);
        });
    };
});

app/code/Cm/CustomerAttribute/etc/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="MagentoCheckoutModelShippingInformationManagement">
         <plugin name="Cm_CustomerAttribute::ShippingInformationManagement" 
 type="CmCustomerAttributePluginCheckoutModelShippingInformationManagement" sortOrder="1"/>
          </type>
      </config>

app/code/Cm/CustomerAttribute/Plugin/Checkout/Model/ShippingInformationManagement.php

   <?php
    namespace CmCustomerAttributePluginCheckoutModel;

  class ShippingInformationManagement
{
    /**
     * @param MagentoCheckoutModelShippingInformationManagement $subject
     * @param $cartId
     * @param MagentoCheckoutApiDataShippingInformationInterface $addressInformation
     */
     protected $helper;
     protected $quoteRepository;
     public function __construct(

    BootsgridCustomerAttributeHelperCustomerattribute $helper,
     MagentoQuoteModelQuoteRepository $quoteRepository
    ) {

        $this->helper = $helper;
         $this->quoteRepository = $quoteRepository;
    }


    public function beforeSaveAddressInformation(
        MagentoCheckoutModelShippingInformationManagement $subject,
        $cartId,
        MagentoCheckoutApiDataShippingInformationInterface $addressInformation
    ) {
       $extensionAttributes = $addressInformation->getShippingAddress();
       $custAttributes = $extensionAttributes->getExtensionAttributes();
       if($custAttributes )
       {
         $quote = $this->quoteRepository->getActive($cartId);


        $customField = $custAttributes->getTestTextarea();
        $cus = $custAttributes->getTestAge();
        $quote->setTestAge($cus);
        $quote->setTestTextarea($customField);



      }
        // error_log(print_r($custAttributes,1));
    }
}

How to save the customer_field dynamically in sales_order and quote order in magento 2

image:

enter image description here
When using extension_attributes.xml file its saved into db but i want to pass a attribute_code dynamically in the xml file

etc/extension_attributes.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
    <extension_attributes for="MagentoQuoteApiDataAddressInterface">
        <attribute code="test_age" type="string" /> * how to pass "test_age" dynamically *
        <attribute code="test_textarea" type="string" />
    </extension_attributes>
</config>

enter image description here


Get this bounty!!!

#StackBounty: #magento2 #customer-attribute #savedata How to save customer attributes dynamically in the checkout register page in mage…

Bounty: 50

I have create a customer attributes which created dynamically from backend its fine works in customer_account_create and customer_account_edit and i was stucked to
saved a customer attributes field data in after save address information in checkout form.

and i followed this link

app/code/ Cm/CustomerAttribute/Model/Plugin/Checkout/LayoutProcessor.php

  <?php
namespace CmCustomerAttributePluginCheckoutBlockCheckout;

class LayoutProcessor
{
    public function __construct(CmCustomerAttributeHelperCustomerattribute $helper)
    {
        $this->helper = $helper;
    }
    public function afterProcess(
        MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
        $jsLayout
    ) {
        $attributeCollection = $this->helper->getUserDefinedAttribures();

       if ($attributeCollection->getSize() > 0) 
       {
         foreach ($attributeCollection as $attribute)

         {
        if ($this->helper->isAttribureForCheckoutRegister($attribute->getAttributeCode()))
        {
        $frontEndLabel = $attribute->getStoreLabel($this->helper->getStoreId());
        $customAttributeCode = $attribute->getAttributeCode();
        $fieldRequiredClass = ($attribute->getIsRequired()) ? 'true' : '' ;
        if($fieldRequiredClass == '')
        {
            $fieldRequiredClass = false;
        }
        $fieldFrontendClass = ($attribute->getFrontendClass()) ? $attribute->getFrontendClass() : '';
        $fieldInput =$attribute->getFrontendInput();
        $attributeId = $attribute->getAttributeId();
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();

        $attributeOptionAll = $objectManager->create(MagentoEavModelResourceModelEntityAttributeOptionCollection::class)
                                    ->setPositionOrder('asc')
                                    ->setAttributeFilter($attributeId)
                                    ->setStoreFilter()
                                    ->load();
        $opt_val = array();
        $allOptions=array();


        foreach ($attributeOptionAll->getData() as $key => $v) 
        {
          // $allid = $v['attribute_id'];
          $opt_val['value'] = $v['option_id'];
          $opt_val['label'] = $v['value'];
          $allOptions[] = $opt_val;
      }
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$customAttributeCode] = $this->addNewField($customAttributeCode,$frontEndLabel, $fieldRequiredClass,  $fieldFrontendClass,$fieldInput,  $allOptions );

        }
      }
    }
    return $jsLayout;
    }

    private function addNewField($customAttributeCode, $frontEndLabel, $fieldRequiredClass,  $fieldFrontendClass, $fieldInput, $allOptions  )
    {
        if($fieldInput == 'text')
        {
            $fieldInputType = 'input';
            $fieldAbstract =  'abstract';
        }
        elseif ($fieldInput == 'date') {
           $fieldInputType = 'date'; 
           $fieldAbstract =  'date';
        }
        elseif ($fieldInput == 'select') {
           $fieldInputType = 'select'; 
           $fieldAbstract =  'select';
        }
        elseif ($fieldInput == 'multiselect') {
           $fieldInputType = 'multiselect'; 
           $fieldAbstract =  'multiselect';

        }
        elseif ($fieldInput == 'boolean') {
           $fieldInputType = 'select'; 
           $fieldAbstract =  'select';
           $allOptions = [
                 ['value' => '0', 'label' => 'No'],
                 ['value' => '1', 'label' => 'Yes']
               ];

        }
         elseif ($fieldInput == 'textarea') {
           $fieldInputType = 'textarea'; 
           $fieldAbstract =  'textarea';

        }
        $customField = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'customEntry' => null,
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                // 'tooltip' => [
                //     'description' => 'this is what the field is for',
                // ],
            ],
            'dataScope' => 'shippingAddress.custom_attributes' . '.' . $customAttributeCode,
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'sortOrder' => 1000,
            'validation' => [$fieldFrontendClass => true , 
                'required-entry' => $fieldRequiredClass],
            'options' =>  $allOptions,
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true,
        ];

         return $customField;
    }
}

image:

enter image description here


Get this bounty!!!

#StackBounty: #magento2 #customer-attribute #savedata How to save a dynamic customer attributes in checkout register page in magento 2?

Bounty: 50

app/code/ Cm/CustomerAttribute/Model/Plugin/Checkout/LayoutProcessor.php

    <?php
namespace CmCustomerAttributeModelPluginCheckout;

class LayoutProcessor
{
    /**
     * @param MagentoCheckoutBlockCheckoutLayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
     public function __construct(CmCustomerAttributeHelperCustomerattribute $helper)
    {
        $this->helper = $helper;
    }

    public function afterProcess(
        MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
        array  $jsLayout
    ) {

 $attributeCollection = $this->helper->getUserDefinedAttribures();

    if ($attributeCollection->getSize() > 0) 
    {
         foreach ($attributeCollection as $attribute)

       {
        if ($this->helper->isAttribureForCheckoutRegister($attribute->getAttributeCode()))
        {
        $frontEndLabel = $attribute->getStoreLabel($this->helper->getStoreId());
        $attributeCode = $attribute->getAttributeCode();
        $getAttributeCodeFunction = "get" .  str_replace(' ', '', ucwords(str_replace('_', ' ', $attribute->getAttributeCode

())));
        $fieldRequiredClass = ($attribute->getIsRequired()) ? 'true' : '' ;
        if($fieldRequiredClass == '')
        {
            $fieldRequiredClass = false;
        }
        $fieldFrontendClass = ($attribute->getFrontendClass()) ? $attribute->getFrontendClass() : '';
        $fieldInput =$attribute->getFrontendInput();
        if($fieldInput == 'text')
        {
            $fieldInputType = 'input';
            $fieldAbstract =  'abstract';
            $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$attributeCode] = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'id' => $attributeCode
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$attributeCode.'',
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' =>[$fieldFrontendClass => true, 
                'required-entry' => $fieldRequiredClass],
            'sortOrder' => 250,
            'id' => $attributeCode
        ];
        }
        elseif ($fieldInput == 'date') {
           $fieldInputType = 'date'; 
           $fieldAbstract =  'date';
           $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$attributeCode] = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'id' => $attributeCode
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$attributeCode.'',
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' =>[$fieldFrontendClass => true , 
                'required-entry' => $fieldRequiredClass],
            'sortOrder' => 250,

            'id' => $attributeCode
        ];
        }
        elseif ($fieldInput == 'select') {
           $fieldInputType = 'select'; 
           $fieldAbstract =  'select';

        $attributeId = $attribute->getAttributeId();
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();

        $attributeOptionAll = $objectManager->create(MagentoEavModelResourceModelEntityAttributeOptionCollection::class)
                                    ->setPositionOrder('asc')
                                    ->setAttributeFilter($attributeId)
                                    ->setStoreFilter()
                                    ->load();
        $opt_val = array();
        $allOptions=array();


        foreach ($attributeOptionAll->getData() as $key => $v) 
        {
          // $allid = $v['attribute_id'];
          $opt_val['value'] = $v['option_id'];
          $opt_val['label'] = $v['value'];
          $allOptions[] = $opt_val;
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$attributeCode] = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'id' => $attributeCode
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$attributeCode.'',
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' =>[$fieldFrontendClass => true , 
                'required-entry' => $fieldRequiredClass],
            'sortOrder' => 250,
             'options' =>  $allOptions,  
            'id' => $attributeCode
        ];

        }
        }
        elseif ($fieldInput == 'multiselect') {
           $fieldInputType = 'input'; 
           $fieldAbstract =  'abstract';

        $attributeId = $attribute->getAttributeId();
        $objectManager = MagentoFrameworkAppObjectManager::getInstance();

        $attributeOptionAll = $objectManager->create(MagentoEavModelResourceModelEntityAttributeOptionCollection::class)
                                    ->setPositionOrder('asc')
                                    ->setAttributeFilter($attributeId)
                                    ->setStoreFilter()
                                    ->load();
        $opt_val = array();
        $allOptions=array();


        foreach ($attributeOptionAll->getData() as $key => $v) 
        {
          // $allid = $v['attribute_id'];
          $opt_val['value'] = $v['option_id'];
          $opt_val['label'] = $v['value'];
          $allOptions[] = $opt_val;
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$attributeCode] = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'id' => $attributeCode
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$attributeCode.'',
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' =>[$fieldFrontendClass => true , 
                'required-entry' => $fieldRequiredClass],
            'sortOrder' => 250,
             // 'options' =>  $allOptions,  
            'id' => $attributeCode
        ];

        }
        }
        elseif ($fieldInput == 'boolean') {
           $fieldInputType = 'select'; 
           $fieldAbstract =  'select';
           $allOptions = [
                 ['value' => '0', 'label' => 'No'],
                 ['value' => '1', 'label' => 'Yes']
               ];
           $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$attributeCode] = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'id' => $attributeCode
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$attributeCode.'',
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' =>[$fieldFrontendClass => true, 
                'required-entry' => $fieldRequiredClass],
            'sortOrder' => 250,
             'options' =>  $allOptions,  
            'id' => $attributeCode
        ];

        }
         elseif ($fieldInput == 'textarea') {
           $fieldInputType = 'textarea'; 
           $fieldAbstract =  'abstract';
           $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children'][$attributeCode] = [
            'component' => 'Magento_Ui/js/form/element/'.$fieldAbstract.'',
            'config' => [
                'customScope' => 'shippingAddress.custom_attributes',
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/'.$fieldInputType.'',
                'id' => $attributeCode
            ],
            'dataScope' => 'shippingAddress.custom_attributes.'.$attributeCode.'',
            'label' => $frontEndLabel,
            'provider' => 'checkoutProvider',
            'visible' => true,
            'validation' =>[$fieldFrontendClass => true, 
                'required-entry' => $fieldRequiredClass],
            'sortOrder' => 250,
            'id' => $attributeCode
        ];

        }



       }
      }
     }
     return $jsLayout;  
    }


}

image:

enter image description here


Get this bounty!!!