Skip to content

Commit

Permalink
Updated control for homepage restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
magemaclean committed May 22, 2020
1 parent 463e14f commit 7a9c1a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public function canAccessSearch($storeId = null) {
return !$this->getConfigData('catalog', 'search', $storeId);
}

public function canAccessHomepage($storeId = null) {
$pageId = $this->scopeConfig->getValue(
'web/default/cms_home_page',
ScopeInterface::SCOPE_STORE,
$storeId
);

return $this->canAccessCmsPage($pageId, $storeId);
}

public function canAccessCmsPage($page, $storeId = null) {
$pages = $this->getConfigData('cms', 'pages', $storeId);
if($pages && !empty($pages)) {
Expand Down
5 changes: 4 additions & 1 deletion Observer/RestrictAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ public function execute(Observer $observer)

$request = $observer->getEvent()->getRequest();
$actionFullName = strtolower($request->getFullActionName());

if($actionFullName === 'cms_noroute_index') {
$noroutePage = $this->_helper->getNoroutePage($storeId);
if(!$this->_helper->canAccessCmsPage($noroutePage, $storeId)) {
return $this->_restrictAccessRedirect($this->_helper->getConfigData("cms", "message", $storeId));
}
} else if($actionFullName === 'cms_index_index') {
if(!$this->_helper->canAccessHomepage($storeId)) {
return $this->_restrictAccessRedirect($this->_helper->getConfigData("cms", "message", $storeId));
}
} else if($actionFullName === 'cms_page_view') {
$pageId = $request->getParam('page_id', false);
if($pageId && !$this->_helper->canAccessCmsPageId($pageId, $storeId)) {
Expand Down

0 comments on commit 7a9c1a3

Please sign in to comment.