0

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 1

0

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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.