2

I am trying to updating the checkout forms telephone field validation. I have achieved this for shipping form but in billing form it is not working.

For this I have done in my di.xml:

<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
    <plugin disabled="false" name="phone_validation_in_billing_form" sortOrder="100"
        type="vendor\module\Plugin\LayoutProcessor"/>
</type> 

And in my LayoutProcessor:

<?php
        namespace vendor\module\Plugin;

        use \Magento\Checkout\Block\Checkout\LayoutProcessor as MagentoLayoutProcessor;


        class LayoutProcessor
        {

            public function afterProcess(MagentoLayoutProcessor $subject, $jsLayout)
            {
            if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                ['payment']['children']['payments-list']['children']
            )) {

                foreach ($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                     ['payment']['children']['payments-list']['children'] as $key => $payment) {

                /* telephone */
                if (isset($payment['children']['form-fields']['children']['telephone'])) {
                    $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
                    ['payment']['children']['payments-list']['children'][$key]['children']['form-fields']['children']
                    ['telephone']['validation'] =  [
                                    'validate-number' => 1,
                                ];
                }


                }

                }
                return $jsLayout;
            }

            }

But nothing happened. My pluging is invoking because when I var_dump the variables it was showing but not doing anything.

Thanks

  • In variable $key I am getting "before-place-order" instead of payment method. I guess thats why its not working – Stack user Aug 14 at 5:59
0

I have found a workaround. I just printed the $jsLayout and then guessed the telephone node manually from array. Here is what worked for me:

<?php

namespace vendor\module\Plugin;

use \Magento\Checkout\Block\Checkout\LayoutProcessor as MagentoLayoutProcessor;

class LayoutProcessor {

    public function afterProcess(MagentoLayoutProcessor $subject, $jsLayout) {
        $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['afterMethods']['children']["billing-address-form"]['children']['form-fields']['children']['telephone']['validation'] = [
                    'validate-number' => 1,
                    "required-entry" => 1,
                    'min_text_length' => 8
        ];

        return $jsLayout;
    }

}

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.