2

I am trying to update the template through di.xml in the admin section. I want to change the template of Admin > Catalog > bundle > option template.

I tried the below code, but it's not working for me.

module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/Module.xsd">
    <module name="Rmsundar_Bundle" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Bundle"/>
        </sequence>
    </module>
</config>

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">
    <type name="Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option">
        <arguments>
            <argument name="template" xsi:type="string">Rmsundar_Bundle::product/edit/bundle/option.phtml</argument>
        </arguments>
    </type>
</config>

2 Answers 2

3

Try this

<?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\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option">
        <arguments>
            <argument name="data"  xsi:type="array">
                <item name="template" xsi:type="string">Rmsundar_Bundle::product/edit/bundle/option.phtml</item>
            </argument>
        </arguments>
    </type>
</config>
7
  • above code is not working Jul 20, 2016 at 4:21
  • This work only if the layout does not overwrite the arguments. Can you describe what you want to achieve?
    – KAndy
    Jul 20, 2016 at 7:01
  • I need to change the template file of an block \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option Jul 20, 2016 at 7:19
  • Why do not use layout for this?
    – KAndy
    Jul 20, 2016 at 8:52
  • 1
0

I found the solution. If we use preference we can override the _construct method, in that we can set the template.

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="Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option" type="Rmsundar\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option" /> 
</config>

Option.php

<?php

namespace Rmsundar\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle;

class Option extends \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option
{
    protected $_template = 'Rmsundar_Bundle::product/edit/bundle/option.phtml';
}

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.