forked from abelbm/magento2-disable-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sophie Shanahan-Kluth
committed
Jun 18, 2020
1 parent
7852e16
commit d6ebe2e
Showing
6 changed files
with
51 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,20 @@ | |
use Magento\Framework\App\Helper\AbstractHelper; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
class Data extends AbstractHelper{ | ||
class Data extends AbstractHelper { | ||
|
||
/** | ||
* Get value from config | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @return mixed | ||
*/ | ||
public function getConfigValue() { | ||
return $this->scopeConfig->getValue( | ||
'admin/disable_frontend/show_frontend_as', ScopeInterface::SCOPE_WEBSITE | ||
); | ||
public function getConfigValue() | ||
{ | ||
return [ | ||
'show_frontend_as' => $this->scopeConfig->getValue('admin/disable_frontend/show_frontend_as', ScopeInterface::SCOPE_WEBSITE), | ||
'redirect_to' => $this->scopeConfig->getValue('admin/disable_frontend/redirect_to', ScopeInterface::SCOPE_WEBSITE), | ||
]; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,17 +15,17 @@ class DisableFrontend implements ObserverInterface { | |
* @var Magento\Framework\App\ActionFlag; | ||
*/ | ||
protected $_actionFlag; | ||
|
||
/** | ||
* @var Magento\Framework\App\Response\RedirectInterface | ||
*/ | ||
protected $redirect; | ||
|
||
/** | ||
* @var Magento\Backend\Helper\Data | ||
*/ | ||
private $helperBackend; | ||
|
||
/** | ||
* @var FocusriteNovation\DisableFrontend\Helper\Data | ||
*/ | ||
|
@@ -51,24 +51,32 @@ public function __construct( | |
$this->helperBackend = $helperBackend; | ||
$this->disableFrontendHelper = $disableFrontendHelper; | ||
} | ||
|
||
/** | ||
* Show an empty page(default) or redirect to Admin site. | ||
* Depend in the config in | ||
* Stores > Configuration > Advanced > Admin > Disable Frontend | ||
* Show an empty page (default) or redirect to a given page. | ||
* | ||
* Config is set in Stores > Configuration > Advanced > Admin > Disable | ||
* Frontend. | ||
* | ||
* @author Abel Bolanos Martinez <[email protected]> | ||
* @param \Magento\Framework\Event\ObserverInterface $observer | ||
* @return void | ||
*/ | ||
public function execute(ObserverInterface $observer) | ||
{ | ||
{ | ||
// Shows a blank page if all else fails. | ||
$this->_actionFlag->set('', Action::FLAG_NO_DISPATCH, true); | ||
|
||
if ($this->disableFrontendHelper->getConfigValue() === 1) { | ||
|
||
$configValue = $this->disableFrontendHelper->getConfigValue(); | ||
|
||
if ($configValue['show_frontend_as'] === 'admin_login') { | ||
// Redirect to admin. | ||
$controller = $observer->getControllerAction(); | ||
$this->redirect->redirect($controller->getResponse(),$this->helperBackend->getHomePageUrl()); | ||
$this->redirect->redirect($controller->getResponse(), $this->helperBackend->getHomePageUrl()); | ||
} | ||
elseif ($configValue['show_frontend_as'] === 'redirect_to') { | ||
// Check that the URL is valid. | ||
// Redirect to that URL. | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters