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

What is the steepest angle that a canal can be traversable without locks?

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

If the Wish spell is used to duplicate the effect of Simulacrum, are existing duplicates destroyed?

Is there a name of the flying bionic bird?

Why could you hear an Amstrad CPC working?

Realistic Alternatives to Dust: What Else Could Feed a Plankton Bloom?

Why is it "Tumoren" and not "Tumore"?

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

Output the Arecibo Message

Understanding the implication of what "well-defined" means for the operation in quotient group

Falsification in Math vs Science

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

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

Is "plugging out" electronic devices an American expression?

What tool would a Roman-age civilization have to grind silver and other metals into dust?

aging parents with no investments

What is the meaning of Triage in Cybersec world?

Does light intensity oscillate really fast since it is a wave?

How to manage monthly salary

How to create dashed lines/arrows in Illustrator

JSON.serialize: is it possible to suppress null values of a map?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

What is the best strategy for white in this position?

Should I write numbers in words or as numerals when there are multiple next to each other?



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 8 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

                              Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                              Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

                              Aasi (pallopeli) Navigointivalikko