Override method in LayoutProcessor The 2019 Stack Overflow Developer Survey Results Are...

Why can Shazam do this?

"To split hairs" vs "To be pedantic"

Is "plugging out" electronic devices an American expression?

How come people say “Would of”?

Springs with some finite mass

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

Carnot-Caratheodory metric

How to create dashed lines/arrows in Illustrator

Why is my p-value correlated to difference between means in two sample tests?

Where does the "burst of radiance" from Holy Weapon originate?

Spanish for "widget"

Pristine Bit Checking

aging parents with no investments

How to make payment on the internet without leaving a money trail?

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

I looked up a future colleague on LinkedIn before I started a job. I told my colleague about it and he seemed surprised. Should I apologize?

Patience, young "Padovan"

Does duplicating a spell with Wish count as casting that spell?

Limit the amount of RAM Mathematica may access?

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

Should I use my personal or workplace e-mail when registering to external websites for work purpose?

What is the meaning of Triage in Cybersec world?

Falsification in Math vs Science

Is flight data recorder erased after every flight?



Override method in LayoutProcessor



The 2019 Stack Overflow Developer Survey Results Are InMagento2 rewrite _prepareCollection method in wishlist returning blank pagemain.CRITICAL: Plugin class doesn't existModel Override issue in magento 2Overridden Cart block does not load templateMagento 2.2.0 - checkout_index_index.xml shippingAdditional not workingMagento 2.2.1: Add Custom Upload file attribute in CheckoutMagento offline custom Payment method with drop down listMagento 2.2.5: Overriding Admin Controller sales/orderOverwrite private method in LayoutProcessor?Magento 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















I want to make changes(PHP code) to the method processPaymentConfiguration, but I don't know how I can override the method so my changes have a higher priority. I can alter the LayoutProcessor file but it's never good to apply changes to a core file.



So my question; is this possible and what do I need to do to achieve this?



Vendor/Module/Block/Checkout/LayoutProcessor.php



<?php
namespace VendorModuleBlockCheckout;

use MagentoFrameworkAppObjectManager;
use MagentoCheckoutBlockCheckoutLayoutProcessorInterface;
use MagentoCustomerModelAttributeMetadataDataProvider;
use MagentoUiComponentFormAttributeMapper;
use MagentoCheckoutBlockCheckoutAttributeMerger;
use MagentoCustomerModelOptions;

class LayoutProcessor implements LayoutProcessorInterface
{
private $attributeMetadataDataProvider;
protected $attributeMapper;
protected $merger;
private $options;

public function __construct(
AttributeMetadataDataProvider $attributeMetadataDataProvider,
AttributeMapper $attributeMapper,
AttributeMerger $merger
) {
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
$this->attributeMapper = $attributeMapper;
$this->merger = $merger;
}

private function getOptions()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getOptions()
}


private function getAddressAttributes()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getAddressAttributes()
}

private function convertElementsToSelect($elements, $attributesToConvert)
{
//same code as Magento/Checkout/Block/LayoutProcessor::convertElementsToSelect()
}

public function process($jsLayout)
{
//same code as Magento/Checkout/Block/LayoutProcessor::process()
}

private function processPaymentConfiguration(array &$configuration, array $elements)
{
/*
code from Magento/Checkout/Block/LayoutProcessor::processPaymentConfiguration()
with a couple changes.
It works when I apply the changes in code file (vendor/magento/magento-checkout/...)
*/
}
}


When I var_dump processPaymentConfigurationfrom the core and my custom code, I get the same results. So it looks like the code executes and returns the right thing but nothing is happening.



Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCheckoutBlockCheckoutLayoutProcessor" type="VendorModuleBlockCheckoutLayoutProcessor" />
</config>









share|improve this question




















  • 1





    Simply override the block. You can achieve this with help of plugin also.

    – Dinesh Yadav
    Jun 7 '17 at 12:19











  • processPaymentConfiguration is private method. So you don't modify even if you overwrite LayoutProcessor class. Create a plugin for LayoutProcessor::process, then you need to modify layout payment config array.

    – Sohel Rana
    Jun 7 '17 at 15:21











  • @SohelRana Why should I modify an array, this doesn't allow me to change a method. Am I missing something?

    – creativename
    Jun 8 '17 at 7:42











  • @DineshYadav I overrided the block, turns out I forgot to update my di.xml, but it still does not work. I've updated my question with my code.

    – creativename
    Jun 9 '17 at 9:26


















3















I want to make changes(PHP code) to the method processPaymentConfiguration, but I don't know how I can override the method so my changes have a higher priority. I can alter the LayoutProcessor file but it's never good to apply changes to a core file.



So my question; is this possible and what do I need to do to achieve this?



Vendor/Module/Block/Checkout/LayoutProcessor.php



<?php
namespace VendorModuleBlockCheckout;

use MagentoFrameworkAppObjectManager;
use MagentoCheckoutBlockCheckoutLayoutProcessorInterface;
use MagentoCustomerModelAttributeMetadataDataProvider;
use MagentoUiComponentFormAttributeMapper;
use MagentoCheckoutBlockCheckoutAttributeMerger;
use MagentoCustomerModelOptions;

class LayoutProcessor implements LayoutProcessorInterface
{
private $attributeMetadataDataProvider;
protected $attributeMapper;
protected $merger;
private $options;

public function __construct(
AttributeMetadataDataProvider $attributeMetadataDataProvider,
AttributeMapper $attributeMapper,
AttributeMerger $merger
) {
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
$this->attributeMapper = $attributeMapper;
$this->merger = $merger;
}

private function getOptions()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getOptions()
}


private function getAddressAttributes()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getAddressAttributes()
}

private function convertElementsToSelect($elements, $attributesToConvert)
{
//same code as Magento/Checkout/Block/LayoutProcessor::convertElementsToSelect()
}

public function process($jsLayout)
{
//same code as Magento/Checkout/Block/LayoutProcessor::process()
}

private function processPaymentConfiguration(array &$configuration, array $elements)
{
/*
code from Magento/Checkout/Block/LayoutProcessor::processPaymentConfiguration()
with a couple changes.
It works when I apply the changes in code file (vendor/magento/magento-checkout/...)
*/
}
}


When I var_dump processPaymentConfigurationfrom the core and my custom code, I get the same results. So it looks like the code executes and returns the right thing but nothing is happening.



Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCheckoutBlockCheckoutLayoutProcessor" type="VendorModuleBlockCheckoutLayoutProcessor" />
</config>









share|improve this question




















  • 1





    Simply override the block. You can achieve this with help of plugin also.

    – Dinesh Yadav
    Jun 7 '17 at 12:19











  • processPaymentConfiguration is private method. So you don't modify even if you overwrite LayoutProcessor class. Create a plugin for LayoutProcessor::process, then you need to modify layout payment config array.

    – Sohel Rana
    Jun 7 '17 at 15:21











  • @SohelRana Why should I modify an array, this doesn't allow me to change a method. Am I missing something?

    – creativename
    Jun 8 '17 at 7:42











  • @DineshYadav I overrided the block, turns out I forgot to update my di.xml, but it still does not work. I've updated my question with my code.

    – creativename
    Jun 9 '17 at 9:26














3












3








3


1






I want to make changes(PHP code) to the method processPaymentConfiguration, but I don't know how I can override the method so my changes have a higher priority. I can alter the LayoutProcessor file but it's never good to apply changes to a core file.



So my question; is this possible and what do I need to do to achieve this?



Vendor/Module/Block/Checkout/LayoutProcessor.php



<?php
namespace VendorModuleBlockCheckout;

use MagentoFrameworkAppObjectManager;
use MagentoCheckoutBlockCheckoutLayoutProcessorInterface;
use MagentoCustomerModelAttributeMetadataDataProvider;
use MagentoUiComponentFormAttributeMapper;
use MagentoCheckoutBlockCheckoutAttributeMerger;
use MagentoCustomerModelOptions;

class LayoutProcessor implements LayoutProcessorInterface
{
private $attributeMetadataDataProvider;
protected $attributeMapper;
protected $merger;
private $options;

public function __construct(
AttributeMetadataDataProvider $attributeMetadataDataProvider,
AttributeMapper $attributeMapper,
AttributeMerger $merger
) {
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
$this->attributeMapper = $attributeMapper;
$this->merger = $merger;
}

private function getOptions()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getOptions()
}


private function getAddressAttributes()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getAddressAttributes()
}

private function convertElementsToSelect($elements, $attributesToConvert)
{
//same code as Magento/Checkout/Block/LayoutProcessor::convertElementsToSelect()
}

public function process($jsLayout)
{
//same code as Magento/Checkout/Block/LayoutProcessor::process()
}

private function processPaymentConfiguration(array &$configuration, array $elements)
{
/*
code from Magento/Checkout/Block/LayoutProcessor::processPaymentConfiguration()
with a couple changes.
It works when I apply the changes in code file (vendor/magento/magento-checkout/...)
*/
}
}


When I var_dump processPaymentConfigurationfrom the core and my custom code, I get the same results. So it looks like the code executes and returns the right thing but nothing is happening.



Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCheckoutBlockCheckoutLayoutProcessor" type="VendorModuleBlockCheckoutLayoutProcessor" />
</config>









share|improve this question
















I want to make changes(PHP code) to the method processPaymentConfiguration, but I don't know how I can override the method so my changes have a higher priority. I can alter the LayoutProcessor file but it's never good to apply changes to a core file.



So my question; is this possible and what do I need to do to achieve this?



Vendor/Module/Block/Checkout/LayoutProcessor.php



<?php
namespace VendorModuleBlockCheckout;

use MagentoFrameworkAppObjectManager;
use MagentoCheckoutBlockCheckoutLayoutProcessorInterface;
use MagentoCustomerModelAttributeMetadataDataProvider;
use MagentoUiComponentFormAttributeMapper;
use MagentoCheckoutBlockCheckoutAttributeMerger;
use MagentoCustomerModelOptions;

class LayoutProcessor implements LayoutProcessorInterface
{
private $attributeMetadataDataProvider;
protected $attributeMapper;
protected $merger;
private $options;

public function __construct(
AttributeMetadataDataProvider $attributeMetadataDataProvider,
AttributeMapper $attributeMapper,
AttributeMerger $merger
) {
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
$this->attributeMapper = $attributeMapper;
$this->merger = $merger;
}

private function getOptions()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getOptions()
}


private function getAddressAttributes()
{
//same code as Magento/Checkout/Block/LayoutProcessor::getAddressAttributes()
}

private function convertElementsToSelect($elements, $attributesToConvert)
{
//same code as Magento/Checkout/Block/LayoutProcessor::convertElementsToSelect()
}

public function process($jsLayout)
{
//same code as Magento/Checkout/Block/LayoutProcessor::process()
}

private function processPaymentConfiguration(array &$configuration, array $elements)
{
/*
code from Magento/Checkout/Block/LayoutProcessor::processPaymentConfiguration()
with a couple changes.
It works when I apply the changes in code file (vendor/magento/magento-checkout/...)
*/
}
}


When I var_dump processPaymentConfigurationfrom the core and my custom code, I get the same results. So it looks like the code executes and returns the right thing but nothing is happening.



Vendor/Module/etc/di.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoCheckoutBlockCheckoutLayoutProcessor" type="VendorModuleBlockCheckoutLayoutProcessor" />
</config>






magento2 checkout overrides payment-methods






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 9 '17 at 8:26







creativename

















asked Jun 7 '17 at 12:09









creativenamecreativename

328




328








  • 1





    Simply override the block. You can achieve this with help of plugin also.

    – Dinesh Yadav
    Jun 7 '17 at 12:19











  • processPaymentConfiguration is private method. So you don't modify even if you overwrite LayoutProcessor class. Create a plugin for LayoutProcessor::process, then you need to modify layout payment config array.

    – Sohel Rana
    Jun 7 '17 at 15:21











  • @SohelRana Why should I modify an array, this doesn't allow me to change a method. Am I missing something?

    – creativename
    Jun 8 '17 at 7:42











  • @DineshYadav I overrided the block, turns out I forgot to update my di.xml, but it still does not work. I've updated my question with my code.

    – creativename
    Jun 9 '17 at 9:26














  • 1





    Simply override the block. You can achieve this with help of plugin also.

    – Dinesh Yadav
    Jun 7 '17 at 12:19











  • processPaymentConfiguration is private method. So you don't modify even if you overwrite LayoutProcessor class. Create a plugin for LayoutProcessor::process, then you need to modify layout payment config array.

    – Sohel Rana
    Jun 7 '17 at 15:21











  • @SohelRana Why should I modify an array, this doesn't allow me to change a method. Am I missing something?

    – creativename
    Jun 8 '17 at 7:42











  • @DineshYadav I overrided the block, turns out I forgot to update my di.xml, but it still does not work. I've updated my question with my code.

    – creativename
    Jun 9 '17 at 9:26








1




1





Simply override the block. You can achieve this with help of plugin also.

– Dinesh Yadav
Jun 7 '17 at 12:19





Simply override the block. You can achieve this with help of plugin also.

– Dinesh Yadav
Jun 7 '17 at 12:19













processPaymentConfiguration is private method. So you don't modify even if you overwrite LayoutProcessor class. Create a plugin for LayoutProcessor::process, then you need to modify layout payment config array.

– Sohel Rana
Jun 7 '17 at 15:21





processPaymentConfiguration is private method. So you don't modify even if you overwrite LayoutProcessor class. Create a plugin for LayoutProcessor::process, then you need to modify layout payment config array.

– Sohel Rana
Jun 7 '17 at 15:21













@SohelRana Why should I modify an array, this doesn't allow me to change a method. Am I missing something?

– creativename
Jun 8 '17 at 7:42





@SohelRana Why should I modify an array, this doesn't allow me to change a method. Am I missing something?

– creativename
Jun 8 '17 at 7:42













@DineshYadav I overrided the block, turns out I forgot to update my di.xml, but it still does not work. I've updated my question with my code.

– creativename
Jun 9 '17 at 9:26





@DineshYadav I overrided the block, turns out I forgot to update my di.xml, but it still does not work. I've updated my question with my code.

– creativename
Jun 9 '17 at 9:26










2 Answers
2






active

oldest

votes


















0














you have to "extend" the class not "implement" interface..



class LayoutProcessor extends MagentoCheckoutBlockCheckoutLayoutProcessor





share|improve this answer































    0















    1. Create your own module if you do not have created it yet.

    2. Implement MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through YourModule/etc/frontend/di.xml.
      Check implementation in MagentoCheckoutBlockCheckoutLayoutProcessor::process as a reference



    3. In your new implementation of LayoutProcessorInterface::process method get all payment methods by



      $paymentList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] ?? null;



    4. Iterate through this payment list and modify layout configuration as needed.


    5. Return modified $jsLayout from your implementation of LayoutProcessorInterface::process method.






    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%2f177893%2foverride-method-in-layoutprocessor%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









      0














      you have to "extend" the class not "implement" interface..



      class LayoutProcessor extends MagentoCheckoutBlockCheckoutLayoutProcessor





      share|improve this answer




























        0














        you have to "extend" the class not "implement" interface..



        class LayoutProcessor extends MagentoCheckoutBlockCheckoutLayoutProcessor





        share|improve this answer


























          0












          0








          0







          you have to "extend" the class not "implement" interface..



          class LayoutProcessor extends MagentoCheckoutBlockCheckoutLayoutProcessor





          share|improve this answer













          you have to "extend" the class not "implement" interface..



          class LayoutProcessor extends MagentoCheckoutBlockCheckoutLayoutProcessor






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 13 '17 at 10:12









          Naveed AsimNaveed Asim

          2,7442317




          2,7442317

























              0















              1. Create your own module if you do not have created it yet.

              2. Implement MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through YourModule/etc/frontend/di.xml.
                Check implementation in MagentoCheckoutBlockCheckoutLayoutProcessor::process as a reference



              3. In your new implementation of LayoutProcessorInterface::process method get all payment methods by



                $paymentList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] ?? null;



              4. Iterate through this payment list and modify layout configuration as needed.


              5. Return modified $jsLayout from your implementation of LayoutProcessorInterface::process method.






              share




























                0















                1. Create your own module if you do not have created it yet.

                2. Implement MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through YourModule/etc/frontend/di.xml.
                  Check implementation in MagentoCheckoutBlockCheckoutLayoutProcessor::process as a reference



                3. In your new implementation of LayoutProcessorInterface::process method get all payment methods by



                  $paymentList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] ?? null;



                4. Iterate through this payment list and modify layout configuration as needed.


                5. Return modified $jsLayout from your implementation of LayoutProcessorInterface::process method.






                share


























                  0












                  0








                  0








                  1. Create your own module if you do not have created it yet.

                  2. Implement MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through YourModule/etc/frontend/di.xml.
                    Check implementation in MagentoCheckoutBlockCheckoutLayoutProcessor::process as a reference



                  3. In your new implementation of LayoutProcessorInterface::process method get all payment methods by



                    $paymentList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] ?? null;



                  4. Iterate through this payment list and modify layout configuration as needed.


                  5. Return modified $jsLayout from your implementation of LayoutProcessorInterface::process method.






                  share














                  1. Create your own module if you do not have created it yet.

                  2. Implement MagentoCheckoutBlockCheckoutLayoutProcessorInterface::process in your module through YourModule/etc/frontend/di.xml.
                    Check implementation in MagentoCheckoutBlockCheckoutLayoutProcessor::process as a reference



                  3. In your new implementation of LayoutProcessorInterface::process method get all payment methods by



                    $paymentList = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'] ?? null;



                  4. Iterate through this payment list and modify layout configuration as needed.


                  5. Return modified $jsLayout from your implementation of LayoutProcessorInterface::process method.







                  share











                  share


                  share










                  answered 1 min 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%2f177893%2foverride-method-in-layoutprocessor%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

                      “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                      How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                      夢乃愛華...