Question

Is anyone have an idea about convert XML to LayoutProcessor format? I have created a layout processor as given below. I need to only those sentence which is defined in XML.

\Magento\Checkout\Block\Checkout\LayoutProcessor

<item name="shipping-address-fieldset" xsi:type="array">
    <item name="children" xsi:type="array">
        <item name="telephone" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Mobile phone number</item>
                <item name="elementTmpl" xsi:type="string">Vendor_Customer/form/element/input</item>
            </item>
            <item name="validation" xsi:type="array">
                <item name="custom-validator-phone" xsi:type="boolean">true</item>
            </item>
        </item>
    </item>
</item>

/app/code/Vendor/Customer/Plugin/Checkout/LayoutProcessorPlugin.php

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']['telephone']['children'] = [

        [
            'config' => ['elementTmpl' => 'ui/form/element/input'],
            'dataScope' => '1',
            'provider' => 'checkoutProvider',
            'validation' => ['custom-validator-phone' => true],
        ]
    ];
    return $jsLayout;
}
Was it helpful?

Solution

Lose the last ['children'].

$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
['shippingAddress']['children']['shipping-address-fieldset']['children']['telephone']

and make 'config' => ['elementTmpl' => 'ui/form/element/input'] look like this

'config' => ['elementTmpl' => 'ui/form/element/input', 'label' => __('Mobile phone number')]

OTHER TIPS

follow the below code.

create di.xml at app/code/Vendor/Extension/frotend/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="checkout_shipping" type="Vendor\Extension\Plugin\Checkout\Model\LayoutProcessor" sortOrder="150"/>
    </type>
</config>

then create plugin file with layoutprocessor.php at Vendor\Extension\Plugin\Checkout\Model\LayoutProcessor.php

<?php
namespace Vendor\Extension\Plugin\Checkout\Model;

use Magento\Checkout\Block\Checkout\LayoutProcessor;

class LayoutProcessor
{
    public function __construct(
        \Magento\Payment\Model\Config $paymentModelConfig
    )
    {
        $this->paymentModelConfig = $paymentModelConfig;
    }

    /* disable company from checkout page */
    public function afterProcess(
        LayoutProcessor $subject,
        array $jsLayout
    ) {
        /* For Disable Company field from checkout page shipping form */
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['telephone'] = [
            'config' => ['elementTmpl' => 'ui/form/element/input'],
        'dataScope' => '1',
        'provider' => 'checkoutProvider',
        'validation' => ['custom-validator-phone' => true],
        ];

        $activePayments = $this->paymentModelConfig->getActiveMethods();
        /* For Disable company field from checkout billing form */
        if (count($activePayments)) {
            foreach ($activePayments as $paymentCode => $payment) {
                $jsLayout['components']['checkout']['children']['steps']['children']
                ['billing-step']['children']['payment']['children']
                ['payments-list']['children'][$paymentCode.'-form']['children']
                ['form-fields']['children']['company'] = [
                    'config' => ['elementTmpl' => 'ui/form/element/input'],
                    'dataScope' => '1',
                     'provider' => 'checkoutProvider',
                     'validation' => ['custom-validator-phone' => true],
                ];
            }
        }

        return $jsLayout;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top