0

I'm trying to add a custom block inside the Order view information on admin. And it's being so weird. I can do it inside other tabs but on Information doesn't work.

Looking at the original layout, sales_order_view.xml:

(...)
<referenceContainer name="left">
    <block class="Magento\Sales\Block\Adminhtml\Order\View\Tabs" name="sales_order_tabs">
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Info" name="order_tab_info" template="order/view/tab/info.phtml">
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Messages" name="order_messages"/>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="order/view/info.phtml"/>
            <block class="Magento\Sales\Block\Adminhtml\Order\View\Items" name="order_items" template="order/view/items.phtml">
(...)
        </block>

        <action method="addTab">
            <argument name="name" xsi:type="string">order_info</argument>
            <argument name="block" xsi:type="string">order_tab_info</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Invoices" name="sales_order_invoice.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_invoices</argument>
            <argument name="block" xsi:type="string">sales_order_invoice.grid.container</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Creditmemos" name="sales_order_creditmemo.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_creditmemos</argument>
            <argument name="block" xsi:type="string">sales_order_creditmemo.grid.container</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Shipments" name="sales_order_shipment.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_shipments</argument>
            <argument name="block" xsi:type="string">sales_order_shipment.grid.container</argument>
        </action>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_history</argument>
            <argument name="block" xsi:type="string">Magento\Sales\Block\Adminhtml\Order\View\Tab\History</argument>
        </action>
        <block class="Magento\Sales\Block\Adminhtml\Order\View\Tab\Transactions" name="sales_transactions.grid.container"/>
        <action method="addTab">
            <argument name="name" xsi:type="string">order_transactions</argument>
            <argument name="block" xsi:type="string">sales_transactions.grid.container</argument>
        </action>
(...)

What I need is to insert a block at the end of the block order_tab_info

So my layout override is:

sales_order_view.xml

<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_tab_info">
            <block class="Gsp\OrderCrm\Block\Adminhtml\Order\View\Custom" name="sales_order_view_custom"
                   template="order/view/custom.phtml"
                   after="-"/>
        </referenceBlock>
    </body>
</page>

And this is actually doing nothing

What is funny is, if I change the referenceBlock for:

sales_order_invoice.grid.container

sales_order_creditmemo.grid.container

sales_order_shipment.grid.container

sales_transactions.grid.container

works

But I need this on the Information tab!

Why the information tab doesn't follow the same nomenclature? it should be like: sales_order.grid.container but the log says doesn't exist.

Also couldn't do it on the comments history, don't know the name it's Magento\Sales\Block\Adminhtml\Order\View\Tab\History this is not the layout block.

2

I don't like this answer but it's the only way I know to move on because I don't even know how to learn to do these things. How did you learn? this is so frustrating.

My temporary solution overrides the entire template that prints the info order tab:

sales_order_view.xml

<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_tab_info" template="Gsp_OrderCrm::order/view/tab/info.phtml"/>
    </body>
</page>

Copy paste

vendor/magento/module-sales/view/adminhtml/templates/order/view/tab/info.phtml

into

app\code\Gsp\OrderCrm\view\adminhtml\templates\order\view\tab\info.phtml

And add my custom section in the end.

Really I have to do that?

I'm only extending the template, and I have to copy paste all the original template?

| improve this answer | |

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.