3

In the LayoutProccesor.php I need to add two lines to the processPaymentConfiguration function. Now since this is a private function I can't write a plugin for it.

private function processPaymentConfiguration(array &$configuration, array $elements)
    {
        $output = [];
        foreach ($configuration as $paymentGroup => $groupConfig) {
            foreach ($groupConfig['methods'] as $paymentCode => $paymentComponent) {
                if (empty($paymentComponent['isBillingAddressRequired'])) {
                    continue;
                }
                $output[$paymentCode . '-form'] = $this->getBillingAddressComponent($paymentCode, $elements);

                // CUSTOMCODE
                unset($output[$paymentCode . '-form']['children']['form-fields']['children']['street']['label']);
               $output[$paymentCode . '-form']['children']['form-fields']['children']['street']['children']['0']['label'] = __('Address');
                // END OF CUSTOM CODE

            }
            unset($configuration[$paymentGroup]['methods']);
        }

        return $output;
    }

I rather not overwrite the LayoutProcessor all together since that might bring problems with other extensions?

I tried adding the two lines to an aroundProcess plugin since that is the only public function in the LayoutProcessor. But that didn't work. It is as if the private function is run after that around plugin? I also tried an after plugin without succes.

Any idea?

I'm trying to add the Address label to the street 0 while being in the checkout with a Downloadable product (so the checkout is a bit different).

I need to do this:

  $jsLayoutResult['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['renders']['children']['checkmo-form']['children']['form-fields']['children']['street']['children']['0']['label'] = __('Address');

I tried:

  • Adding it to an around plugin on process
  • Adding it to an after plugin on process

If i add it directly in the LayoutProcessor.php then the code works so the lines of code are definitely correct. But since that is back practice it isn't an option.

Overwriting the whole LayoutProcessor is bad practice too since I'm creating a checkout and other extensions still need to work.

Any idea?

2 Answers 2

1

It could be that your plugin isn't running for some reason. In any case, I don't think it really matters as having needed to the same thing in my previous project I didn't go with a plugin but an additional layout processor instead.

As you're trying to modify the layout and not the behaviour of the layout processor you're referencing, it makes sense for you to do that too.

Here we define a new layout process in etc/frontend/di.xml as follows:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Block\Onepage">
        <arguments>
            <argument name="layoutProcessors" xsi:type="array">
                <item name="checkoutCustomisations" xsi:type="object">Namespace\Module\Block\Checkout\Onepage\LayoutProcessor</item>
            </argument>
        </arguments>
    </type>
</config>

And then the code looked for the layout processor looks somewhat like this (my full class does a bunch of other bits and pieces):

<?php

namespace Namespace\Module\Block\Checkout\Onepage;

class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcessorInterface
{

    public function process($jsLayout)
    {
        foreach($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
        ['children']['payment']['children']['payments-list']['children'] as $methodFormCode => &$methodFormLayout) {
            if(isset(
                $methodFormLayout['children'],
                $methodFormLayout['children']['form-fields'],
                $methodFormLayout['children']['form-fields']['children']
            )) {
                // Street labels
                unset($methodFormLayout['children']['form-fields']['children']['street']['label']);

                $methodFormLayout['children']['form-fields']['children']['street']['children'][0]['label'] = __('Address Line 1');

                $methodFormLayout['children']['form-fields']['children']['street']['children'][1]['label'] = __('Address Line 2');

            }

        }

        return $jsLayout;
    }

}
7
  • Ah this works, thanks. Do you have any clue with the around plugin doesn't work and adding an extra layoutprocessor does? Is it a timing problem or something?
    – Sanne
    Jul 26, 2018 at 14:10
  • 1
    Excellent, glad to hear that @Sanne. Really hard to tell without seeing more code and trying it out in action honestly. Magento always has a curve ball to throw at you. Jul 27, 2018 at 9:51
  • Haha true, it isn't the easiest framework to work with, especially the checkout part xD
    – Sanne
    Jul 28, 2018 at 10:08
  • How to add css to the new field? Oct 25, 2019 at 12:19
  • That's impossible to answer succinctly @jibingeorge other than to say you need to add styles either to your module or theme devdocs.magento.com/guides/v2.3/frontend-dev-guide/… Oct 28, 2019 at 11:36
0

It has already been modified as a plugin in the source, modifying beforeProcess so this might help:

vendor/magento/module-payment/Plugin/PaymentConfigurationProcess

di.xml

<type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
    <plugin name="ProcessPaymentConfiguration" type="Magento\Payment\Plugin\PaymentConfigurationProcess"/>
</type>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.