Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExpressRedirect.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  protected $_actionFlag;
16 
20  protected $_objectManager;
21 
27  protected $_customerSession;
28 
36  public function __construct(
37  \Magento\Framework\App\ActionFlag $actionFlag,
38  \Magento\Framework\ObjectManagerInterface $objectManager,
39  \Magento\Customer\Model\Session $customerSession,
40  \Magento\Framework\App\Helper\Context $context
41  ) {
42  $this->_actionFlag = $actionFlag;
43  $this->_objectManager = $objectManager;
44  $this->_customerSession = $customerSession;
45 
46  parent::__construct($context);
47  }
48 
55  public function redirectLogin(RedirectLoginInterface $expressRedirect, $customerBeforeAuthUrlDefault = null)
56  {
57  $this->_actionFlag->set('', 'no-dispatch', true);
58  foreach ($expressRedirect->getActionFlagList() as $actionKey => $actionFlag) {
59  $this->_actionFlag->set('', $actionKey, $actionFlag);
60  }
61 
62  $expressRedirect->getResponse()->setRedirect(
63  $this->_objectManager->get(
64  \Magento\Framework\Url\Helper\Data::class
65  )->addRequestParam(
66  $expressRedirect->getLoginUrl(),
67  ['context' => 'checkout']
68  )
69  );
70 
71  $customerBeforeAuthUrl = $customerBeforeAuthUrlDefault;
72  if ($expressRedirect->getCustomerBeforeAuthUrl()) {
73  $customerBeforeAuthUrl = $expressRedirect->getCustomerBeforeAuthUrl();
74  }
75  if ($customerBeforeAuthUrl) {
76  $this->_customerSession->setBeforeAuthUrl($customerBeforeAuthUrl);
77  }
78  }
79 }
$objectManager
Definition: bootstrap.php:17
__construct(\Magento\Framework\App\ActionFlag $actionFlag, \Magento\Framework\ObjectManagerInterface $objectManager, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\App\Helper\Context $context)
redirectLogin(RedirectLoginInterface $expressRedirect, $customerBeforeAuthUrlDefault=null)