@@ -27,6 +27,9 @@ class ActionPredispatch implements \Magento\Framework\Event\ObserverInterface
2727 protected $ urlParts = [];
2828
2929 protected $ storeManager ;
30+
31+ protected $ settings ;
32+
3033 private $ resultFactory ;
3134
3235 public function __construct (
@@ -38,6 +41,7 @@ public function __construct(
3841 \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
3942 \Magento \Framework \Controller \ResultFactory $ resultFactory ,
4043 \Magento \Store \Model \StoreManagerInterface $ storeManager ,
44+ \Experius \PageNotFound \Helper \Settings $ settings
4145
4246 ) {
4347 $ this ->url = $ url ;
@@ -48,32 +52,34 @@ public function __construct(
4852 $ this ->scopeConfig = $ scopeConfig ;
4953 $ this ->resultFactory = $ resultFactory ;
5054 $ this ->storeManager = $ storeManager ;
51-
55+ $ this -> settings = $ settings ;
5256 }
5357
54- private function isEnabled ()
55- {
56- $ configValue = $ this ->scopeConfig ->getValue ('pagenotfound/general/enabled ' ,\Magento \Store \Model \ScopeInterface::SCOPE_STORE );
57- return $ configValue ? explode (', ' ,$ configValue ) : [];
58- }
5958
60- private function includedParamsInRedirect ( )
59+ protected function shouldExcludeUrl ( $ url )
6160 {
62- $ configValue = $ this ->scopeConfig ->getValue ('pagenotfound/general/included_params_redirect ' ,\Magento \Store \Model \ScopeInterface::SCOPE_STORE );
63- return $ configValue ? explode (', ' ,$ configValue ) : [];
64- }
61+ $ excludeList = $ this ->settings ->getExcludeList ();
62+ if (empty ($ excludeList )) {
63+ return false ;
64+ }
6565
66- private function includedParamsInFromUrl ()
67- {
68- $ configValue = $ this ->scopeConfig ->getValue ('pagenotfound/general/included_params_from_url ' ,\Magento \Store \Model \ScopeInterface::SCOPE_STORE );
69- return $ configValue ? explode (', ' ,$ configValue ) : [];
66+ $ urlPath = parse_url ($ url , PHP_URL_PATH );
67+ $ urlPath = ltrim ($ urlPath , '/ ' );
68+
69+ foreach ($ excludeList as $ excludeItem ) {
70+ if (strpos ($ urlPath , $ excludeItem ) !== false ) {
71+ return true ;
72+ }
73+ }
74+
75+ return false ;
7076 }
7177
7278 public function execute (
7379 \Magento \Framework \Event \Observer $ observer
7480 ) {
7581
76- if (!$ this ->isEnabled ()){
82+ if (!$ this ->settings -> isEnabled ()){
7783 return ;
7884 }
7985
@@ -86,7 +92,11 @@ public function execute(
8692
8793 $ this ->urlParts = parse_url ($ this ->url ->getCurrentUrl ());
8894
89- $ this ->savePageNotFound ($ this ->getCurrentUrl ());
95+ $ currentUrl = $ this ->getCurrentUrl ();
96+
97+ if (!$ this ->shouldExcludeUrl ($ currentUrl )) {
98+ $ this ->savePageNotFound ($ currentUrl );
99+ }
90100
91101 }
92102
@@ -173,7 +183,7 @@ protected function getParams($redirect=true){
173183
174184 $ queryArray = $ this ->getRequest ()->getParams ();
175185
176- $ unsetParams = ($ redirect ) ? $ this ->includedParamsInRedirect () : $ this ->includedParamsInFromUrl ();
186+ $ unsetParams = ($ redirect ) ? $ this ->settings -> includedParamsInRedirect () : $ this -> settings ->includedParamsInFromUrl ();
177187
178188 foreach ($ queryArray as $ key =>$ value ){
179189
0 commit comments