Create plugin LayoutProcessor::process vs override checkout_index_index.xml
XML Checkout. Should think about XML first.
1) A standard practice
Most of the developer will take a look the XML first to check the XML layout.
2) Maintenance
If you're familiar with checkout XML, you will see that it's easy to change. On the other hand, LayoutProcessor::process()
will be "messy" if there are one more changes from different extensions.
When do we need to use LayoutProcessor::process()
plugin?
1) Complex logic
It's hard to say in this case. But for example:
\Magento\Checkout\Block\Checkout\LayoutProcessor::process($jsLayout)
......
['payment']['children'] = $this->processPaymentChildrenComponents(
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children'],
$elements
);
......
We need to assign the billing info to each payment. As we can see, it's impossible to use XML.
2) Remove component completely
We can use XML to disable a component, but component still is rendered. We can remove this component completely.
XML:
<item name="%the_component_to_be_disabled%" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentDisabled" xsi:type="boolean">true</item>
</item>
</item>
LayoutProcessor::process()
unset($jsLayout['components']['checkout']['children']['steps'][%path_to_target_node%]); //%path_to_target_node% is the path to the component's node in checkout_index_index.xml
return $jsLayout;
3) Can do what XML cannot do...
Don't need to explain more here.