9
9
namespace Magefan \LoginAsCustomer \Controller \Adminhtml \Login ;
10
10
11
11
/**
12
- * LoginAsCustomer login action
12
+ * Class Login
13
+ * @package Magefan\LoginAsCustomer\Controller\Adminhtml\Login
13
14
*/
14
15
class Login extends \Magento \Backend \App \Action
15
16
{
17
+ /**
18
+ * @var \Magefan\LoginAsCustomer\Model\Login
19
+ */
20
+ protected $ login ;
21
+ /**
22
+ * @var \Magento\Backend\Model\Auth\Session
23
+ */
24
+ protected $ session = null ;
25
+ /**
26
+ * @var \Magento\Store\Model\StoreManagerInterface
27
+ */
28
+ protected $ storeManager = null ;
29
+ /**
30
+ * @var \Magento\Framework\Url
31
+ */
32
+ protected $ url = null ;
33
+ /**
34
+ * Login constructor.
35
+ * @param \Magento\Backend\App\Action\Context $context
36
+ * @param \Magefan\LoginAsCustomer\Model\Login $login
37
+ */
38
+ public function __construct (
39
+ \Magento \Backend \App \Action \Context $ context ,
40
+ \Magefan \LoginAsCustomer \Model \Login $ login = null ,
41
+ \Magento \Backend \Model \Auth \Session $ session = null ,
42
+ \Magento \Store \Model \StoreManagerInterface $ storeManager = null ,
43
+ \Magento \Framework \Url $ url = null
44
+ ) {
45
+ parent ::__construct ($ context );
46
+ $ objectManager = $ this ->_objectManager ;
47
+ $ this ->login = $ login ?: $ objectManager ->get (\Magefan \LoginAsCustomer \Model \Login::class);
48
+ $ this ->session = $ session ?: $ objectManager ->get (\Magento \Backend \Model \Auth \Session::class);
49
+ $ this ->storeManager = $ storeManager ?: $ objectManager ->get (\Magento \Store \Model \StoreManagerInterface::class);
50
+ $ this ->url = $ url ?: $ objectManager ->get (\Magento \Framework \Url::class);
51
+ }
16
52
/**
17
53
* Login as customer action
18
54
*
@@ -22,9 +58,7 @@ public function execute()
22
58
{
23
59
$ customerId = (int ) $ this ->getRequest ()->getParam ('customer_id ' );
24
60
25
- $ login = $ this ->_objectManager
26
- ->create (\Magefan \LoginAsCustomer \Model \Login::class)
27
- ->setCustomerId ($ customerId );
61
+ $ login = $ this ->login ->setCustomerId ($ customerId );
28
62
29
63
$ login ->deleteNotUsed ();
30
64
@@ -36,22 +70,18 @@ public function execute()
36
70
return ;
37
71
}
38
72
39
- $ user = $ this ->_objectManager -> get (\ Magento \ Backend \ Model \ Auth \Session::class) ->getUser ();
73
+ $ user = $ this ->session ->getUser ();
40
74
$ login ->generate ($ user ->getId ());
41
75
$ customerStoreId = $ this ->getCustomerStoreId ($ customer );
42
76
43
- $ storeManager = $ this ->_objectManager ->get (\Magento \Store \Model \StoreManagerInterface::class);
44
-
45
77
if ($ customerStoreId ) {
46
- $ store = $ storeManager ->getStore ($ customerStoreId );
78
+ $ store = $ this -> storeManager ->getStore ($ customerStoreId );
47
79
} else {
48
- $ store = $ storeManager ->getDefaultStoreView ();
80
+ $ store = $ this -> storeManager ->getDefaultStoreView ();
49
81
}
50
82
51
- $ url = $ this ->_objectManager ->get (\Magento \Framework \Url::class)
52
- ->setScope ($ store );
53
-
54
- $ redirectUrl = $ url ->getUrl ('loginascustomer/login/index ' , ['secret ' => $ login ->getSecret (), '_nosid ' => true ]);
83
+ $ redirectUrl = $ this ->url ->setScope ($ store )
84
+ ->getUrl ('loginascustomer/login/index ' , ['secret ' => $ login ->getSecret (), '_nosid ' => true ]);
55
85
56
86
$ this ->getResponse ()->setRedirect ($ redirectUrl );
57
87
}
0 commit comments