getRequest()->getParam('id'); $customerId = (int)$this->customerSession->getCustomerId(); $connection = $this->resource->getConnection(); $exists = $connection->fetchOne( $connection->select() ->from($this->resource->getTableName('esun_legacy_order'), ['legacy_order_id']) ->where('legacy_order_id = ?', $legacyOrderId) ->where('customer_id = ?', $customerId) ); if (!$exists) { $this->messageManager->addErrorMessage(__('The historical order could not be found.')); return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT) ->setPath('legacy_order/account/index'); } $page = $this->pageFactory->create(); $page->getConfig()->getTitle()->set(__('Historical Order')); return $page; } }