How to display previous page after validation (logging in)?
-
19-12-2020 - |
Question
In my store I create PDF file for each order, that can only be accessed by customer. To validate if user can access order I first check if order was created by:
guest (then
\Magento\Sales\Helper\Guest $guestAuthorization
and$guestAuthorization->loadValidOrder($request)
. False returns resultRedirect Object)registered user (then
\Magento\Sales\Controller\AbstractController\OrderViewAuthorization $loggedAuthorization
and$loggedAuthorization->canView($order)
. False returns FALSE and I create resultRedirect Object$resultRedirect = $this->_resultRedirectFactory->create();$resultRedirect->setUrl('/customer/account/login');
The problem is once user verifies either by logging in or guest order form I want to redirect him to previous URL (the PDF file). What is the easiest way to achieve this?
Solution
Try before you redirect the customer to login the following
$this->customerSession->setBeforeAuthUrl('url_to_your_pdf');
where the customerSession is an instance of
\Magento\Customer\Model\Session $customerSession,