2

I have added a custom form in the shipping address before-form handle. This form is validating for a guest checkout process but not working for logged in customers who have already added address information.

Below is my Layoutprocessor file where am injecting the custom field to shipping step before-form handle.

$customAttributeCode = 'experience_survey_option';
       $customField = [
        'component' => 'Magento_Ui/js/form/element/select',
        'config' => [
            'customScope' => 'shippingAddress.custom_attributes',
            'template' => 'ui/form/field',
            'elementTmpl' => 'ui/form/element/select',
            'id' => 'drop-down',
        ],
        'dataScope' => 'shippingAddress.custom_attributes.experience_survey_option',
        'label' => $this->getSelectLabel(),
        'provider' => 'checkoutProvider',
        'visible' => true,
        'validation' => ['required-entry' => true],
        'sortOrder' => 150,
        'id' => 'drop-down',
        'options' => $this->getSelectOptions()
    ];
    $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['before-form']['children']['experience-survey-form']['children']['experience-survey-checkout-form-fieldset']['children'][$customAttributeCode] = $customField;

Also am attaching the screenshots of checkout form.

  1. Guest checkout

guest checkout

2.Logged in customer checkout

logged in customer checkout

Any help will be appreciated. Thanks.

2
  • any updates here ?
    – Radhu
    Mar 23, 2020 at 4:22
  • Good question did you manage to get anything. kind on need this one too! May 22, 2020 at 15:09

1 Answer 1

0

Below code will help to place the field above to the shipping field

$attributeCode = 'delivery_note';
        $fieldConfiguration = [
            'component' => 'Magento_Ui/js/form/element/textarea',
            'config' => [
                'customScope' => 'shippingAddress.extension_attributes',
                'customEntry' => null,
                'template' => 'ui/form/field',
                'elementTmpl' => 'ui/form/element/textarea',
                'tooltip' => [
                    'description' => 'Here you can leave delivery notes',
                ],
            ],
            'dataScope' => 'shippingAddress.extension_attributes' . '.' . $attributeCode,
            'label' => 'Delivery Notes',
            'provider' => 'checkoutProvider',
            'sortOrder' => 1000,
            'validation' => [
                'required-entry' => true
            ],
            'options' => [],
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true,
            'value' => ''
        ];

        $jsLayout['components']['checkout']['children']
        ['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['before-shipping-method-form']
        ['children'][$attributeCode] = $fieldConfiguration;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.