cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Block in admin Order view of Magento 2

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Custom Block in admin Order view of Magento 2

 How to add custom block in Admin>Sale>Order view ? I have tried many ways but nothing work for me.

please guide me a correct way of doing this. i am working on custom shipping extension of magento2. 

 

Thanks..

8 REPLIES 8

Re: Custom Block in admin Order view of Magento 2

You can just add custom block in order view page of admin panel,

 

create sales_order_view.xml file, at path, app/code/Vendor/Modulename/view/adminhtml/layout/sales_order_view.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="order_tab_info">
            <block class="Vendor\Modulename\Block\Custom" name="custom_block_view" template="Vendor_Modulename::tracking/custom.phtml">
            </block>
        </referenceBlock>
    </body>
</page>

Where Vendor\Modulename replace with your Modulename.

 

If issue solved, Click Kudos/Accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom Block in admin Order view of Magento 2

Thank you so much for your response @Rakesh Jesadiya 

i have created form.php and preview.php in my Block>Adminhtml>Order>View> , please clear it to me i have to give what instead of "custom block " ? in your posted code. 

 

Re: Custom Block in admin Order view of Magento 2

<?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="order_tab_info">
            <block class="Vendor\Modulename\Block\Adminhtml\Order\View\Form" name="custom_block_view" template="Vendor_Modulename::tracking/custom.phtml">
            </block>
        </referenceBlock>
    </body>
</page>

 Where 

Vendor_Modulename replace with your module and set your phtml instead of custom.phtml file.

 if issue solved, click kudos/accept as solutions.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom Block in admin Order view of Magento 2

I have replaced this but not showing block . 

Re: Custom Block in admin Order view of Magento 2

 In /Tcs/Codshippingbooking/view/Adminhtml/templates/order/view/custom.phtml have  : 

<h1>My custom Block</h1>

In Tcs/Codshippingbooking/view/Adminhtml/layout/sales_order_view.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="order_tab_info">
            <block class="Tcs\Codshippingbooking\Block\Custom" name="custom_block_view" template="Tcs_Codshippingbooking::tracking/custom.phtml">
            </block>
        </referenceBlock>
    </body>
</page>

In Tcs/Codshippingbooking/Block/Adminhtml/Order/View/Custom.php 

<?php
namespace Tcs\Codshippingbooking\Block\Adminhtml\Order\View;
class Custom extends \Magento\Backend\Block\Template
{

}

where I am wrong ? 

Re: Custom Block in admin Order view of Magento 2

You dont given full class path and wrong template link in your xml file,

Update with below one,

 

<?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="order_tab_info">
            <block class="Tcs\Codshippingbooking\Block\Adminhtml\Order\View\Custom" name="custom_block_view" template="Tcs_Codshippingbooking::order/view/custom.phtml">
            </block>
        </referenceBlock>
    </body>
</page>

Remove var/generation folder.

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom Block in admin Order view of Magento 2

This won't work. The template 

order/view/tab/info.phtml

doesn't call childHtml custom_block_view so it won't show up.

you have to override order_tab_info template as well which is the above phtml mentioned.

Re: Custom Block in admin Order view of Magento 2

You can add custom block using reference container order_additional_info;

create sales_order_view.xml file, at path, app/code/Vendor/Modulename/view/adminhtml/layout/sales_order_view.xml

 

<referenceContainer name="order_additional_info">
    <block class="Tcs\Codshippingbooking\Block\Adminhtml\Order\View\Custom" name="custom_block_view" template="Tcs_Codshippingbooking::order/view/custom.phtml">        
    </block>
</referenceContainer>

 

create Custom.php file, at path, app/code/Tcs/Codshippingbooking/Block/Adminhtml/Order/View/Custom.php

 

<?php
namespace Tcs\Codshippingbooking\Block\Adminhtml\Order\View;
class Custom extends \Magento\Backend\Block\Template
{
}

create Custom.phtml file, at path, app/code/Tcs/Codshippingbooking/view/adminhtml/templates/order/view/Custom.phtml

 

<section class="admin__page-section tcs-shipping-block">
    <div class="admin__page-section-title"><strong class="title"><?= $block->escapeHtml(__('TCS SHIPPING BLOCK')) ?></strong></div>    
</section>

If issue solved, Click Kudos as solutions.