Create plugin LayoutProcessor::process vs override checkout_index_index.xml The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)magento 2 add custom fields to checkout form below shipping address formHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Validation Error with jQuery-UI Autocomplete and KnockoutJs - Magento 2Magento 2.2.0 - checkout_index_index.xml shippingAdditional not workingMagento 2.2.1: Add Custom Upload file attribute in CheckoutMagento 2.2.5: Overriding Admin Controller sales/orderTrying to add field to checkout with LayoutProcessor PluginMagento 2.2.5: Add, Update and Delete existing products Custom Options
Who or what is the being for whom Being is a question for Heidegger?
How many people can fit inside Mordenkainen's Magnificent Mansion?
Was credit for the black hole image misattributed?
How to pronounce 1ターン?
Wolves and sheep
Can a 1st-level character have an ability score above 18?
Can the prologue be the backstory of your main character?
How does ice melt when immersed in water?
What information about me do stores get via my credit card?
Can a novice safely splice in wire to lengthen 5V charging cable?
Segmentation fault output is suppressed when piping stdin into a function. Why?
How did passengers keep warm on sail ships?
What was the last x86 CPU that did not have the x87 floating-point unit built in?
How to remove this toilet supply line that seems to have no nut?
Is above average number of years spent on PhD considered a red flag in future academia or industry positions?
Take groceries in checked luggage
When did F become S in typeography, and why?
Cooking pasta in a water boiler
First use of “packing” as in carrying a gun
What do you call a plan that's an alternative plan in case your initial plan fails?
Problems with Ubuntu mount /tmp
How should I replace vector<uint8_t>::const_iterator in an API?
Does Parliament need to approve the new Brexit delay to 31 October 2019?
Can the DM override racial traits?
Create plugin LayoutProcessor::process vs override checkout_index_index.xml
The 2019 Stack Overflow Developer Survey Results Are In
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)magento 2 add custom fields to checkout form below shipping address formHow can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Validation Error with jQuery-UI Autocomplete and KnockoutJs - Magento 2Magento 2.2.0 - checkout_index_index.xml shippingAdditional not workingMagento 2.2.1: Add Custom Upload file attribute in CheckoutMagento 2.2.5: Overriding Admin Controller sales/orderTrying to add field to checkout with LayoutProcessor PluginMagento 2.2.5: Add, Update and Delete existing products Custom Options
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
To add a custom field, I can create a plugin and it will add input on the checkout.
1) Create plugin LayoutProcessor::process
Exapmle :
Namespace/Module/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
<plugin name="add_custom_field_checkout_form" type="NamespaceModuleModelPluginCheckoutLayoutProcessor" sortOrder="100"/>
</type>
</config>
Namespace/Module/Model/Plugin/Checkout/LayoutProcessor.php
<?php
namespace NamespaceModuleModelPluginCheckout;
class LayoutProcessor
public function afterProcess(
MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
array $jsLayout
)
$jsLayout['components']['checkout']['children']['steps']
['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']
['children']['custom_field'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input',
'options' => [],
'id' => 'custom-field'
],
'dataScope' => 'shippingAddress.custom_attributes.custom_field',
'label' => 'Custom Field',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => [],
'sortOrder' => 250,
'id' => 'custom-field'
];
return $jsLayout;
2) Override checkout_index_index.xml
But there is another way, when I can expand checkout_index_index.xml.
For example, I'll add a checkbox :
Namespace/Module/view/frontend/layout/checkout_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Modifying an existing step-->
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="before-form" xsi:type="array">
<item name="children" xsi:type="array">
<item name="newsletter" xsi:type="array">
<item name="component" xsi:type="string">Namespace_Module/js/view/newsletter</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Next, I will create these files :
Namespace/Module/view/frontend/web/js/view/newsletter.js
Namespace/Module/view/frontend/web/template/newsletter.html
And get the checkbox on the form.
Question : Tell me please, in order to change the checkout, when should I create plugin LayoutProcessor::process and when to override checkout_index_index.xml?
magento2 checkout layout xml
add a comment |
To add a custom field, I can create a plugin and it will add input on the checkout.
1) Create plugin LayoutProcessor::process
Exapmle :
Namespace/Module/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
<plugin name="add_custom_field_checkout_form" type="NamespaceModuleModelPluginCheckoutLayoutProcessor" sortOrder="100"/>
</type>
</config>
Namespace/Module/Model/Plugin/Checkout/LayoutProcessor.php
<?php
namespace NamespaceModuleModelPluginCheckout;
class LayoutProcessor
public function afterProcess(
MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
array $jsLayout
)
$jsLayout['components']['checkout']['children']['steps']
['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']
['children']['custom_field'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input',
'options' => [],
'id' => 'custom-field'
],
'dataScope' => 'shippingAddress.custom_attributes.custom_field',
'label' => 'Custom Field',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => [],
'sortOrder' => 250,
'id' => 'custom-field'
];
return $jsLayout;
2) Override checkout_index_index.xml
But there is another way, when I can expand checkout_index_index.xml.
For example, I'll add a checkbox :
Namespace/Module/view/frontend/layout/checkout_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Modifying an existing step-->
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="before-form" xsi:type="array">
<item name="children" xsi:type="array">
<item name="newsletter" xsi:type="array">
<item name="component" xsi:type="string">Namespace_Module/js/view/newsletter</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Next, I will create these files :
Namespace/Module/view/frontend/web/js/view/newsletter.js
Namespace/Module/view/frontend/web/template/newsletter.html
And get the checkbox on the form.
Question : Tell me please, in order to change the checkout, when should I create plugin LayoutProcessor::process and when to override checkout_index_index.xml?
magento2 checkout layout xml
add a comment |
To add a custom field, I can create a plugin and it will add input on the checkout.
1) Create plugin LayoutProcessor::process
Exapmle :
Namespace/Module/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
<plugin name="add_custom_field_checkout_form" type="NamespaceModuleModelPluginCheckoutLayoutProcessor" sortOrder="100"/>
</type>
</config>
Namespace/Module/Model/Plugin/Checkout/LayoutProcessor.php
<?php
namespace NamespaceModuleModelPluginCheckout;
class LayoutProcessor
public function afterProcess(
MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
array $jsLayout
)
$jsLayout['components']['checkout']['children']['steps']
['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']
['children']['custom_field'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input',
'options' => [],
'id' => 'custom-field'
],
'dataScope' => 'shippingAddress.custom_attributes.custom_field',
'label' => 'Custom Field',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => [],
'sortOrder' => 250,
'id' => 'custom-field'
];
return $jsLayout;
2) Override checkout_index_index.xml
But there is another way, when I can expand checkout_index_index.xml.
For example, I'll add a checkbox :
Namespace/Module/view/frontend/layout/checkout_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Modifying an existing step-->
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="before-form" xsi:type="array">
<item name="children" xsi:type="array">
<item name="newsletter" xsi:type="array">
<item name="component" xsi:type="string">Namespace_Module/js/view/newsletter</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Next, I will create these files :
Namespace/Module/view/frontend/web/js/view/newsletter.js
Namespace/Module/view/frontend/web/template/newsletter.html
And get the checkbox on the form.
Question : Tell me please, in order to change the checkout, when should I create plugin LayoutProcessor::process and when to override checkout_index_index.xml?
magento2 checkout layout xml
To add a custom field, I can create a plugin and it will add input on the checkout.
1) Create plugin LayoutProcessor::process
Exapmle :
Namespace/Module/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCheckoutBlockCheckoutLayoutProcessor">
<plugin name="add_custom_field_checkout_form" type="NamespaceModuleModelPluginCheckoutLayoutProcessor" sortOrder="100"/>
</type>
</config>
Namespace/Module/Model/Plugin/Checkout/LayoutProcessor.php
<?php
namespace NamespaceModuleModelPluginCheckout;
class LayoutProcessor
public function afterProcess(
MagentoCheckoutBlockCheckoutLayoutProcessor $subject,
array $jsLayout
)
$jsLayout['components']['checkout']['children']['steps']
['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']
['children']['custom_field'] = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' => [
'customScope' => 'shippingAddress.custom_attributes',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input',
'options' => [],
'id' => 'custom-field'
],
'dataScope' => 'shippingAddress.custom_attributes.custom_field',
'label' => 'Custom Field',
'provider' => 'checkoutProvider',
'visible' => true,
'validation' => [],
'sortOrder' => 250,
'id' => 'custom-field'
];
return $jsLayout;
2) Override checkout_index_index.xml
But there is another way, when I can expand checkout_index_index.xml.
For example, I'll add a checkbox :
Namespace/Module/view/frontend/layout/checkout_index_index.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Modifying an existing step-->
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="before-form" xsi:type="array">
<item name="children" xsi:type="array">
<item name="newsletter" xsi:type="array">
<item name="component" xsi:type="string">Namespace_Module/js/view/newsletter</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
Next, I will create these files :
Namespace/Module/view/frontend/web/js/view/newsletter.js
Namespace/Module/view/frontend/web/template/newsletter.html
And get the checkbox on the form.
Question : Tell me please, in order to change the checkout, when should I create plugin LayoutProcessor::process and when to override checkout_index_index.xml?
magento2 checkout layout xml
magento2 checkout layout xml
asked May 28 '18 at 15:59
Evgeniy KapelkoEvgeniy Kapelko
1,1761317
1,1761317
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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:
MagentoCheckoutBlockCheckoutLayoutProcessor::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.
add a comment |
First of all you do not obligatory need to create a plugin as "Customizations implemented through plugins SHOULD be adjusted respectively" according to Magento 2 Technical Guidelines: https://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines.html.
The problem with plugins is that they influence the performance. Plugins SHOULD NOT be used within own module. Besides plugins can impact the sort order and your plugin can be called before necessary layout processor.
That's why if you want to customize Magento 2 checkout think about either:
- Usage of checkout_index_index.xml in your module. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_customize.html for more details.
- Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check MagentoCheckoutBlockCheckoutLayoutProcessor.php::process for more details.
Usage of LayoutProcessorInterface gives you ability to handle dynamic attributes. For example, you need to customize billing step on checkout and display custom component on all payment methods. In your implementation of LayoutProcessorInterface you can get all payment methods and build layout configuration with your custom component for all of them dynamically.
Or for example in your implementation of LayoutProcessorInterface you can dynamically add or not add your custom components to the js block Layout depending on configuration.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f227762%2fcreate-plugin-layoutprocessorprocess-vs-override-checkout-index-index-xml%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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:
MagentoCheckoutBlockCheckoutLayoutProcessor::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.
add a comment |
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:
MagentoCheckoutBlockCheckoutLayoutProcessor::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.
add a comment |
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:
MagentoCheckoutBlockCheckoutLayoutProcessor::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.
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:
MagentoCheckoutBlockCheckoutLayoutProcessor::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.
answered May 31 '18 at 3:54
Khoa TruongDinhKhoa TruongDinh
22.2k64187
22.2k64187
add a comment |
add a comment |
First of all you do not obligatory need to create a plugin as "Customizations implemented through plugins SHOULD be adjusted respectively" according to Magento 2 Technical Guidelines: https://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines.html.
The problem with plugins is that they influence the performance. Plugins SHOULD NOT be used within own module. Besides plugins can impact the sort order and your plugin can be called before necessary layout processor.
That's why if you want to customize Magento 2 checkout think about either:
- Usage of checkout_index_index.xml in your module. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_customize.html for more details.
- Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check MagentoCheckoutBlockCheckoutLayoutProcessor.php::process for more details.
Usage of LayoutProcessorInterface gives you ability to handle dynamic attributes. For example, you need to customize billing step on checkout and display custom component on all payment methods. In your implementation of LayoutProcessorInterface you can get all payment methods and build layout configuration with your custom component for all of them dynamically.
Or for example in your implementation of LayoutProcessorInterface you can dynamically add or not add your custom components to the js block Layout depending on configuration.
add a comment |
First of all you do not obligatory need to create a plugin as "Customizations implemented through plugins SHOULD be adjusted respectively" according to Magento 2 Technical Guidelines: https://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines.html.
The problem with plugins is that they influence the performance. Plugins SHOULD NOT be used within own module. Besides plugins can impact the sort order and your plugin can be called before necessary layout processor.
That's why if you want to customize Magento 2 checkout think about either:
- Usage of checkout_index_index.xml in your module. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_customize.html for more details.
- Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check MagentoCheckoutBlockCheckoutLayoutProcessor.php::process for more details.
Usage of LayoutProcessorInterface gives you ability to handle dynamic attributes. For example, you need to customize billing step on checkout and display custom component on all payment methods. In your implementation of LayoutProcessorInterface you can get all payment methods and build layout configuration with your custom component for all of them dynamically.
Or for example in your implementation of LayoutProcessorInterface you can dynamically add or not add your custom components to the js block Layout depending on configuration.
add a comment |
First of all you do not obligatory need to create a plugin as "Customizations implemented through plugins SHOULD be adjusted respectively" according to Magento 2 Technical Guidelines: https://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines.html.
The problem with plugins is that they influence the performance. Plugins SHOULD NOT be used within own module. Besides plugins can impact the sort order and your plugin can be called before necessary layout processor.
That's why if you want to customize Magento 2 checkout think about either:
- Usage of checkout_index_index.xml in your module. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_customize.html for more details.
- Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check MagentoCheckoutBlockCheckoutLayoutProcessor.php::process for more details.
Usage of LayoutProcessorInterface gives you ability to handle dynamic attributes. For example, you need to customize billing step on checkout and display custom component on all payment methods. In your implementation of LayoutProcessorInterface you can get all payment methods and build layout configuration with your custom component for all of them dynamically.
Or for example in your implementation of LayoutProcessorInterface you can dynamically add or not add your custom components to the js block Layout depending on configuration.
First of all you do not obligatory need to create a plugin as "Customizations implemented through plugins SHOULD be adjusted respectively" according to Magento 2 Technical Guidelines: https://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines.html.
The problem with plugins is that they influence the performance. Plugins SHOULD NOT be used within own module. Besides plugins can impact the sort order and your plugin can be called before necessary layout processor.
That's why if you want to customize Magento 2 checkout think about either:
- Usage of checkout_index_index.xml in your module. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_customize.html for more details.
- Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check MagentoCheckoutBlockCheckoutLayoutProcessor.php::process for more details.
Usage of LayoutProcessorInterface gives you ability to handle dynamic attributes. For example, you need to customize billing step on checkout and display custom component on all payment methods. In your implementation of LayoutProcessorInterface you can get all payment methods and build layout configuration with your custom component for all of them dynamically.
Or for example in your implementation of LayoutProcessorInterface you can dynamically add or not add your custom components to the js block Layout depending on configuration.
edited Apr 10 at 3:23
answered Apr 10 at 3:02
transversustransversus
212
212
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f227762%2fcreate-plugin-layoutprocessorprocess-vs-override-checkout-index-index-xml%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown