From 7a9c1a393a81af1ba8c4239b0125f9beffc3e11a Mon Sep 17 00:00:00 2001 From: Chris MacLean Date: Fri, 22 May 2020 20:16:34 +0700 Subject: [PATCH] Updated control for homepage restriction --- Helper/Data.php | 10 ++++++++++ Observer/RestrictAccess.php | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Helper/Data.php b/Helper/Data.php index 92a72f9..e931a02 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -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)) { diff --git a/Observer/RestrictAccess.php b/Observer/RestrictAccess.php index fd8f2a4..3db4a02 100644 --- a/Observer/RestrictAccess.php +++ b/Observer/RestrictAccess.php @@ -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)) {