2

I am trying to override following file

module-bundle/view/adminhtml/layout/sales_order_creditmemo_new.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="order_items">
            <block class="Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer" as="bundle" template="sales/creditmemo/create/items/renderer.phtml"/>
        </referenceBlock>
    </body>
</page>

I override it by creating same name layout file in my module

Vendor_App/view/adminhtml/layout/sales_order_creditmemo_new.xml

<referenceBlock name="order_items">
    <block class="Vendor\App\Block\Adminhtml\Sales\Order\Items\Renderer" as="bundle" template="Vendor_App::sales/creditmemo/create/items/renderer.phtml"/>
</referenceBlock>

But my class and template are not overridden. I have created the class and phtml in my module.

I tried to override it using di.xml by adding following code.

<preference for="Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer" type="Vendor\App\Block\Adminhtml\Sales\Order\Items\Renderer"/>

And this works, but the problem is, on clicking Update Qty's button, it fetches my template instead of its own template as the layout for Update Qty is different.

I tried above thing with Configurable and simple product both works perfectly, only bundle type is creating issue.

2 Answers 2

6

You can use setChild() to replace a block by its alias. First create the new block with a name, then call setChild() via <action>:

<referenceBlock name="order_items">
    <block class="Vendor\App\Block\Adminhtml\Sales\Order\Items\Renderer" name="custom_renderer" template="Vendor_App::sales/creditmemo/create/items/renderer.phtml"/>

    <action method="setChild">
        <argument name="alias" xsi:type="string">bundle</argument>
        <argument name="block" xsi:type="string">custom_renderer</argument>
    </action>
</referenceBlock>
5
  • Thanks Fabian for a reply, but after going with your answer I'm getting following error 1 exception(s): Exception #0 (Exception): Warning: Illegal offset type in /Applications/MAMP/htdocs/magentoce21/vendor/magento/framework/Data/Structure.php on line 472
    – Nausif
    Jul 7, 2017 at 9:23
  • @Nausif I forgot xsi:type="string" in the argument nodes, that might be the problem Jul 7, 2017 at 9:47
  • @FabianSchmengler will this work with <arguments> instead of <action>? As <action> has been deprecated.
    – Ben Crook
    Jul 7, 2017 at 9:57
  • @BenCrook I don't think so, but I'm not sure, did not look into the inner workins of <arguments> yet. Jul 7, 2017 at 11:11
  • It does not work, I am trying to override cart item deafult template. "checkout_cart_item_renderers.xml" Feb 1, 2018 at 13:34
0

Please check my answer here: https://magento.stackexchange.com/a/239387/14403

I believe that is the same solution you are looking for.

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.