1212use Magento \Store \Model \ScopeInterface ;
1313use Magento \Framework \App \Config \ScopeConfigInterface ;
1414use Magefan \Blog \Model \NoSlashUrlRedirect ;
15+ use Magefan \Blog \Model \SlashUrlRedirect ;
1516
1617/**
1718 * Class Predispath Frontend Blog Action Controller Observer
@@ -23,6 +24,11 @@ class PredispathFrontendBlogActionControllerObserver implements ObserverInterfac
2324 */
2425 protected $ noSlashUrlRedirect ;
2526
27+ /**
28+ * @var SlashUrlRedirect
29+ */
30+ protected $ slashUrlRedirect ;
31+
2632 /**
2733 * @var ScopeConfigInterface
2834 */
@@ -32,13 +38,17 @@ class PredispathFrontendBlogActionControllerObserver implements ObserverInterfac
3238 * PredispathFrontendBlogActionControllerObserver constructor.
3339 * @param ScopeConfigInterface $scopeConfig
3440 * @param NoSlashUrlRedirect $noSlashUrlRedirect
41+ * @param SlashUrlRedirect $slashUrlRedirect
3542 */
3643 public function __construct (
3744 ScopeConfigInterface $ scopeConfig ,
38- NoSlashUrlRedirect $ noSlashUrlRedirect
45+ NoSlashUrlRedirect $ noSlashUrlRedirect ,
46+ SlashUrlRedirect $ slashUrlRedirect = null
3947 ) {
4048 $ this ->scopeConfig = $ scopeConfig ;
4149 $ this ->noSlashUrlRedirect = $ noSlashUrlRedirect ;
50+ $ this ->slashUrlRedirect = $ slashUrlRedirect ?: \Magento \Framework \App \ObjectManager::getInstance ()
51+ ->get (\Magefan \Blog \Model \SlashUrlRedirect::class);
4252 }
4353
4454 /**
@@ -47,18 +57,29 @@ public function __construct(
4757 */
4858 public function execute (\Magento \Framework \Event \Observer $ observer )
4959 {
50- $ redirectToNoSlash = $ this ->scopeConfig ->getValue (
51- Config::XML_PATH_REDIRECT_TO_NO_SLASH ,
52- ScopeInterface::SCOPE_STORE
53- );
54-
5560 $ advancedPermalinkEnabled = $ this ->scopeConfig ->getValue (
5661 Config::XML_PATH_ADVANCED_PERMALINK_ENABLED ,
5762 ScopeInterface::SCOPE_STORE
5863 );
5964
60- if ($ redirectToNoSlash && !$ advancedPermalinkEnabled ) {
65+ if ($ advancedPermalinkEnabled ) {
66+ $ redirectToNoSlash = $ this ->scopeConfig ->getValue (
67+ Config::XML_PATH_REDIRECT_TO_NO_SLASH_BLOG_PLUS ,
68+ ScopeInterface::SCOPE_STORE
69+ );
70+ } else {
71+ $ redirectToNoSlash = $ this ->scopeConfig ->getValue (
72+ Config::XML_PATH_REDIRECT_TO_NO_SLASH ,
73+ ScopeInterface::SCOPE_STORE
74+ );
75+ }
76+
77+ if ($ redirectToNoSlash ) {
6178 $ this ->noSlashUrlRedirect ->execute ($ observer );
79+ } else {
80+ $ this ->slashUrlRedirect ->execute ($ observer );
6281 }
6382 }
83+
84+
6485}
0 commit comments