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..
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.
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.
<?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.
I have replaced this but not showing block .
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 ?
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.
This won't work. The template
order/view/tab/info.phtmldoesn'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.
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.