0

I am trying to add a block to the configure screen of bundled products in the create order form of admin.

I added this layout file: My/Module/view/adminhtml/layout/catalog_product_view_type_bundle.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.composite.fieldset.bundle">
            <block class="My\Module\Block\Adminhtml\FooBar" name="product.composite.fieldset.bundle.foobar" template="My_Module::foobar.phtml" after="-"/>
        </referenceBlock>
    </body>
</page>

I added this block file: My/Module/Block/Adminhtml/FooBar.php

<?php
namespace My\Module\Block\Adminhtml;

class FooBar extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context
    ) {
        parent::__construct($context);
    }

    public function sayHello()
    {
        return __('hello');
    }
}

I added this template file: My/Module/view/adminhtml/templates/foobar.phtml

<?php echo "<h1>HELLO HELLO HELLO</h1>"; ?>

And finally I clear the cache and compile:

magento c:c
magento s:d:c

But I don't see any big-ole HELLOs in the page. What am I doing wrong?

0

The short answer is that 'Magento/Bundle/view/adminhtml/templates/product/composite/fieldset/options/bundle.phtml' doesn't call 'getChildHtml()' so my block is never rendered. The block is there, just not rendered.

To fix this, I added my block to the 'product.composite.fieldset' block and just placed it before the bundled items like this:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="product.composite.fieldset">
            <block class="Xplorie\AttractionSide\Block\Adminhtml\Catalog\Product\Composite\Fieldset\Availability" name="product.composite.fieldset.availability" template="Xplorie_AttractionSide::product/composite/fieldset/availability.phtml" before="-"/>
        </referenceBlock>

    </body>
</page>

Works but I would prefer to mess around with the actual 'product.composite.fieldset.bundle' block. But that can't be done without a little trickery (I guess: replace the template, call my own, ...etc).

Perhaps somebody else has a better idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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