0

I have created one module that has created Customer Attribute called Title:

For that i have created layout processor Vendor/Modulename/Plugin/Checkout/Model/Checkout/LayoutProcessor.php

      class LayoutProcessor
 {
/**
 * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
 * @param array $jsLayout
 * @return array
 */
public function afterProcess(
    \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
    array  $jsLayout
) {
    $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
    ['shippingAddress']['children']['shipping-address-fieldset']['children']['delivery_date'] = [
        'component' => 'Magento_Ui/js/form/element/abstract',
        'config' => [
            'customScope' => 'shippingAddress',
            'template' => 'ui/form/field',
            'elementTmpl' => 'ui/form/element/date',
            'options' => [],
            'id' => 'delivery-date'
        ],
        'dataScope' => 'shippingAddress.delivery_date',
        'label' => 'Delivery Date',
        'provider' => 'checkoutProvider',
        'visible' => true,
        'validation' => [],
        'sortOrder' => 250,
        'id' => 'delivery-date'
    ];

    $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
    ['shippingAddress']['children']['shipping-address-fieldset']['children']['cutitle'] = [
        'component' => 'Magento_Ui/js/form/element/select',
        'config' => [
            'customScope' => 'shippingAddress',
            'template' => 'ui/form/field',
            'elementTmpl' => 'ui/form/element/select',
            'id' => 'drop-down',
        ],
        'dataScope' => 'shippingAddress.cutitle',
        'label' => 'Drop Down',
        'provider' => 'checkoutProvider',
        'visible' => true,
        'validation' => [],
        'sortOrder' => 251,
        'id' => 'cutitle',
        'options' => [
            [
                'value' => '',
                'label' => 'Please Select',
            ],
            [
                'value' => 'mrs',
                'label' => 'Mrs.',
            ],
            [
                'value' => 'mr',
                'label' => 'Mr.',
            ]

        ]
    ];

     return $jsLayout;
   }

Plugin: 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="dipen_add_custom_field" type="Vendor\Modulename\Plugin\Checkout\Model\Checkout\LayoutProcessor" sortOrder="100"/>
   </type>



   </config>

I want to save dropdown attribute value and it should show in admin order. What's missing?

Any help would be appreciated.

0

many thanks for your question, it is a very useful question for us all willing to modify Magento 2 checkout.
I have changed the id "cutitle" from your field to "prefix" and that fixes the issue or I believe it does:
- the title value of your drop down is saved correctly and the field name prefix has this data.
- the data does not appear in the address rendering but I understand you are trying to saved this prefix first and foremost?

  • Hi, thanks for your reply. I have added dropdown on checkout page using layout processor but how can i save it? It should show in order as well. Is there anyway i can save it once order place? Do i need to develop any method to show it in admin or it will do automatically? – jack May 8 '18 at 4:43
  • If your dropdown is the Customer Title that appears in your code snippet, I can see it, I have succeeded to save the customer title from your dropdown against the order. Not sure whether this means applying my answer does not work for you? – Herve Tribouilloy May 9 '18 at 7:03

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.