3

I need to move the VAT field to top, I can not find the file with the form or the file where I can modify it

1
  • can you post the snapshot of the page. Mar 11 '17 at 11:54
4

To change the sort order of fields on Checkout you need a LayoutProcessorPlugin.

'namespace/module/etc/frontend/di.xml'

...
<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
    <plugin name="checkout-sort-order-plugin" type="Namespace\Module\Model\Checkout\LayoutProcessorPlugin" sortOrder="10"/>
</type>
...

Now, lets create the plugin.

<?php

namespace Namespace\Module\Model\Checkout;

class LayoutProcessorPlugin
{

/**
 * @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']['vat_id'] = [
        'component' => 'Magento_Ui/js/form/element/abstract',
        'label' => __('VAT number'),
        'config' => [
            'customScope' => 'shippingAddress',
            'template' => 'ui/form/field',
            'elementTmpl' => 'ui/form/element/input',
        ],
        'provider' => 'checkoutProvider',
        'dataScope' => 'shippingAddress.vat_id',
        'sortOrder' => 1,
    ];
    return $jsLayout;
    }
}

You can change the 'sortOrder' => 1, to place it between any two fields you want, but now, with value 1 is placed before all fields Checkout.

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.