0

I have tried validate if render referenceBlock in checkout layout, but it does not work.

I added block Vendor\Module\Block\Index in layout after referenceBlock

Vendor/Module/view/frontend/layout/checkout_index_index.xml

<referenceBlock name="checkout.root">
        <block class="ElTiempo\Efecty\Block\Index" name="is_book">
            <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">
                                        <item name="billing-step" xsi:type="array">
                                            <item name="component" xsi:type="string">uiComponent</item>
                                            <item name="children" xsi:type="array">
                                                <item name="payment" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="renders" xsi:type="array">
                                                            <!-- merge payment method renders here -->
                                                            <item name="children" xsi:type="array">
                                                                <item name="efecty" xsi:type="array">
                                                                    <item name="component" xsi:type="string">Vendor_Module/js/view/payment/method-renderer</item>
                                                                    <item name="methods" xsi:type="array">
                                                                        <item name="efecty" xsi:type="array">
                                                                            <item name="isBillingAddressRequired" xsi:type="boolean">true</item>
                                                                        </item>
                                                                    </item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </block>
    </referenceBlock>

In block validate if render with _toHtml() method

Vendor/Module/Block/Index.php

namespace ElTiempo\Efecty\Block;

class Index extends \Magento\Framework\View\Element\Template
{

    /**
     * Render block HTML
     *
     * @return string
     */
    protected function _toHtml()
    {
        $isBook = true;

        if ($isBook) {
            return parent::_toHtml();
        }
        return '';
    }
}

Any ideas would be the error?

Thanks!

1 Answer 1

0

I found a solution with official documentation and another answer:

https://developer.adobe.com/commerce/php/tutorials/frontend/custom-checkout/customize-view/

For remove a component in checkout layout xml first create a block LayoutProcessor implementing the \Magento\Checkout\Block\Checkout\LayoutProcessorInterface interface with process method (LayoutProcessorInterface::process($jsLayout))

Vendor/Module/Block/Checkout/OurLayoutProcessor.php

<?php

namespace Vendor\Module\Block\Checkout;

use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;

class OurLayoutProcessor implements LayoutProcessorInterface
{
    /**
     * @param array $jsLayout
     * @return array
     */
    public function process($jsLayout)
    {
        unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['renders']['children']['efecty']);
        return $jsLayout;
    }
}

Then create Dependency Injection and add the layout processor

Vendor/Module/etc/di.xml

<type name="Vendor\Checkout\Block\Onepage">
        <arguments>
            <argument name="layoutProcessors" xsi:type="array">
                <item name="ourLayoutProcessor" xsi:type="object">Vendor\Module\Block\Checkout\OurLayoutProcessor</item>
            </argument>
        </arguments>
    </type>

I hope someone can use this answer

Greetings!

Your Answer

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

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