Create plugin LayoutProcessor::process vs override checkout_index_index.xml The 2019 Stack Overflow Developer Survey Results Are Inmagento 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

Why is the maximum length of OpenWrt’s root password 8 characters?

Why do UK politicians seemingly ignore opinion polls on Brexit?

Geography at the pixel level

What is a mixture ratio of propellant?

Does a dangling wire really electrocute me if I'm standing in water?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

How was Skylab's orbit inclination chosen?

A poker game description that does not feel gimmicky

Unbreakable Formation vs. Cry of the Carnarium

Are there any other methods to apply to solving simultaneous equations?

What is this 4-propeller plane?

Why can Shazam do this?

What does "sndry explns" mean in one of the Hitchhiker's guide books?

Why is Grand Jury testimony secret?

Can't find the latex code for the ⍎ (down tack jot) symbol

Inline version of a function returns different value than non-inline version

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

What is the best strategy for white in this position?

Is it possible for the two major parties in the UK to form a coalition with each other instead of a much smaller party?

"Riffle" two strings

Idiomatic way to prevent slicing?

Why don't Unix/Linux systems traverse through directories until they find the required version of a linked library?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

How come people say “Would of”?



Create plugin LayoutProcessor::process vs override checkout_index_index.xml



The 2019 Stack Overflow Developer Survey Results Are Inmagento 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;








3















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?










share|improve this question




























    3















    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?










    share|improve this question
























      3












      3








      3








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 28 '18 at 15:59









      Evgeniy KapelkoEvgeniy Kapelko

      1,1661317




      1,1661317




















          2 Answers
          2






          active

          oldest

          votes


















          6














          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.






          share|improve this answer






























            0














            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:



            1. 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.

            2. Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html 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.





            share























              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
              );



              );













              draft saved

              draft discarded


















              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









              6














              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.






              share|improve this answer



























                6














                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.






                share|improve this answer

























                  6












                  6








                  6







                  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.






                  share|improve this answer













                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 31 '18 at 3:54









                  Khoa TruongDinhKhoa TruongDinh

                  22.2k64187




                  22.2k64187























                      0














                      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:



                      1. 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.

                      2. Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html 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.





                      share



























                        0














                        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:



                        1. 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.

                        2. Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html 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.





                        share

























                          0












                          0








                          0







                          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:



                          1. 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.

                          2. Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html 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.





                          share













                          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:



                          1. 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.

                          2. Implementing MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through di.xml. Check https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html 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.






                          share











                          share


                          share










                          answered 7 mins ago









                          transversustransversus

                          212




                          212



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Nidaros erkebispedøme

                              Birsay

                              Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?