1
1
<?php
2
2
namespace Abelbm \DisableFrontend \Observer ;
3
3
use Magento \Framework \Event \ObserverInterface ;
4
+ use Magento \Framework \App \ActionFlag ;
5
+ use Magento \Framework \App \Response \RedirectInterface ;
6
+ use Magento \Backend \Helper \Data ;
7
+ use Abelbm \DisableFrontend \Helper \Data as DisableFrontendHelper ;
4
8
5
9
class DisableFrontend implements ObserverInterface{
6
10
7
11
protected $ _actionFlag ;
8
12
protected $ redirect ;
9
- private $ HelperBackend ;
13
+ private $ helperBackend ;
10
14
private $ logger ;
11
-
15
+ private $ disableFrontendHelper ;
16
+
12
17
/**
13
- *
14
- * @author Abel Bolanos Martinez <[email protected] >
15
- * @param \Magento\Framework\App\ActionFlag $actionFlag
16
- * @param \Magento\Framework\Message\ManagerInterface $messageManager
17
- * @param \Magento\Framework\App\Response\RedirectInterface $redirect
18
- * @param \Magento\Backend\Helper\Data $HelperBackend
18
+ * DisableFrontend constructor.
19
+ *
20
+ * @author Abel Bolanos Martinez <[email protected] >
21
+ * @param ActionFlag $actionFlag
22
+ * @param RedirectInterface $redirect
23
+ * @param Data $helperBackend
24
+ * @param DisableFrontendHelper $disableFrontendHelper
19
25
* @param \Psr\Log\LoggerInterface $logger
20
26
*/
21
27
public function __construct (
22
- \Magento \Framework \App \ActionFlag $ actionFlag ,
23
- \Magento \Framework \App \Response \RedirectInterface $ redirect ,
24
- \Magento \Backend \Helper \Data $ HelperBackend ,
28
+ ActionFlag $ actionFlag ,
29
+ RedirectInterface $ redirect ,
30
+ Data $ helperBackend ,
31
+ DisableFrontendHelper $ disableFrontendHelper ,
25
32
\Psr \Log \LoggerInterface $ logger
26
33
) {
27
34
$ this ->_actionFlag = $ actionFlag ;
28
35
$ this ->redirect = $ redirect ;
29
- $ this ->HelperBackend = $ HelperBackend ;
36
+ $ this ->helperBackend = $ helperBackend ;
30
37
$ this ->logger = $ logger ;
38
+ $ this ->disableFrontendHelper = $ disableFrontendHelper ;
31
39
}
32
40
33
41
/**
42
+ * Show an empty page(default) or redirect to Admin site.
43
+ * Depend in the config in
44
+ * Stores > Configuration > Advanced > Admin > Disable Frontend
34
45
*
35
46
* @author Abel Bolanos Martinez <[email protected] >
36
47
* @param \Magento\Framework\Event\Observer $observer
37
48
* @return void
38
49
*/
39
50
public function execute (\Magento \Framework \Event \Observer $ observer ){
40
-
41
- //$this->logger->info('TEST LOGGER ');
51
+
52
+ //$this->logger->info('TEST');
42
53
43
54
$ this ->_actionFlag ->set ('' , \Magento \Framework \App \Action \Action::FLAG_NO_DISPATCH , true );
44
55
45
- //custom redirect
46
- //$controller = $observer->getControllerAction();
47
- //$this->redirect->redirect($controller->getResponse(),$this->HelperBackend->getHomePageUrl());
56
+ if ($ this ->disableFrontendHelper ->getConfigValue ()){//redirect to Admin
57
+ $ controller = $ observer ->getControllerAction ();
58
+ $ this ->redirect ->redirect ($ controller ->getResponse (),$ this ->helperBackend ->getHomePageUrl ());
59
+ }
48
60
}
49
61
}
0 commit comments