In magento 2 is there any way to create same order view page in custom module? I want to create a custom order view page where I have to display some more data but not want to display on core (order view page). So for that I need to create a custom a page same as order view page
1 Answer
Step 1:
Create frontname_controllerdirectory_controllerclass.xml inside your module view/adminhtml/layout
Then copy all the layout of sales_order_view.xml from vendor/magento/module-sales/view/adminhtml/layout
Then add custom block or your logic you want to implement and create redirect to your link frontname_controllerdirectory_controllerclass
and create View.php class inside Controller/Adminhtml then define
<?php
namespace Namespace\ModuleName\Controller\Adminhtml\Order;
use Magento\Backend\App\Action;
class View extends \Magento\Sales\Controller\Adminhtml\Order
{
const ADMIN_RESOURCE = 'Namespace_ModuleName::actions_view';
const PAGE_TITLE = 'Add page title here';
public function execute()
{
$order = $this->_initOrder();
$resultRedirect = $this->resultRedirectFactory->create();
if ($order) {
try {
$resultPage = $this->_initAction();
$resultPage->getConfig()->getTitle()->prepend(__('Page title'));
} catch (\Exception $e) {
$this->logger->critical($e);
$this->messageManager->addErrorMessage(__('Exception occurred during order load'));
$resultRedirect->setPath('yourfrontname/order/index');
return $resultRedirect;
}
$resultPage->getConfig()->getTitle()->prepend(sprintf("#%s", $order->getIncrementId()));
return $resultPage;
}
$resultRedirect->setPath('yourfrontname/*/');
return $resultRedirect;
}
}