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 $guestAuthorizationand$guestAuthorization->loadValidOrder($request). False returns resultRedirect Object)

  • registered user (then \Magento\Sales\Controller\AbstractController\OrderViewAuthorization $loggedAuthorizationand$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?

Was it helpful?

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,
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top