diff --git a/Helper/Settings.php b/Helper/Settings.php index bb5051a..2bc88b0 100644 --- a/Helper/Settings.php +++ b/Helper/Settings.php @@ -16,6 +16,7 @@ class Settings extends AbstractHelper const IS_CRON_ENABLED = 'pagenotfound/cron_config/is_cron_enabled'; const CONFIG_DAYS_TO_CLEAN = 'pagenotfound/cron_config/days_to_clean'; const DELETE_NOT_EMPTY_REDIRECT = 'pagenotfound/cron_config/delete_not_empty_redirect'; + const GET_EXCLUDED_URLS = 'pagenotfound/general/exclude_url'; /** * @param Context $context @@ -50,4 +51,16 @@ public function getDeleteNotEmpyRedirect() return $this->scopeConfig->getValue(self::DELETE_NOT_EMPTY_REDIRECT); } + /** + * @return array|string[] + */ + public function getExcludedUrls() + { + $excludedUrls = $this->scopeConfig->getValue(self::GET_EXCLUDED_URLS); + if ($excludedUrls) { + return explode(',', $excludedUrls); + } + return []; + } + } diff --git a/Observer/Controller/ActionPredispatch.php b/Observer/Controller/ActionPredispatch.php index 0077025..7c52379 100644 --- a/Observer/Controller/ActionPredispatch.php +++ b/Observer/Controller/ActionPredispatch.php @@ -27,8 +27,11 @@ class ActionPredispatch implements \Magento\Framework\Event\ObserverInterface protected $urlParts = []; protected $storeManager; + private $resultFactory; + protected $setting; + public function __construct( \Magento\Framework\UrlInterface $url, \Experius\PageNotFound\Model\PageNotFoundFactory $pageNotFoundFactory, @@ -38,6 +41,7 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Controller\ResultFactory $resultFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, + \Experius\PageNotFound\Helper\Settings $setting ) { $this->url = $url; @@ -48,6 +52,7 @@ public function __construct( $this->scopeConfig = $scopeConfig; $this->resultFactory = $resultFactory; $this->storeManager = $storeManager; + $this->setting = $setting; } @@ -86,8 +91,11 @@ public function execute( $this->urlParts = parse_url($this->url->getCurrentUrl()); - $this->savePageNotFound($this->getCurrentUrl()); + if(in_array($this->urlParts['path'],$this->setting->getExcludedUrls())) { + return; + } + $this->savePageNotFound($this->getCurrentUrl()); } /* @return \Magento\Framework\App\RequestInterface */ diff --git a/composer.json b/composer.json index 804a055..d482c4b 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,10 @@ { "name": "Simon Vianen", "email": "simonvianen@experius.nl" + }, + { + "name": "Jeffrey Leeuw", + "email": "jeffreyleeuw@happyhorizon.com" } ], "minimum-stability": "dev", diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 26fad68..635e3cd 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -20,6 +20,10 @@ comma separated. For example language,p,id + + + Enter all the URLs you want to exclude from the 'Page Not Found' module, separated by commas. +