44
55class RedirectWithoutStoreCode implements \Magento \Framework \Event \ObserverInterface
66{
7- /**
8- * @var \Magento\Framework\App\Response\RedirectInterface
9- */
10- protected $ redirect ;
11-
127 /**
138 * @var \Magento\Framework\App\ActionFlag
149 */
@@ -31,20 +26,17 @@ class RedirectWithoutStoreCode implements \Magento\Framework\Event\ObserverInter
3126
3227 /**
3328 *
34- * @param \Magento\Framework\App\Response\RedirectInterface $redirect
3529 * @param \Magento\Framework\App\ActionFlag $actionFlag
3630 * @param \Magento\Store\Model\StoreManagerInterface $storeManager
3731 * @param \Noon\HideDefaultStoreCode\Helper\Data $helper
3832 * @param \Magento\Framework\UrlInterface $url
3933 */
4034 public function __construct (
41- \Magento \Framework \App \Response \RedirectInterface $ redirect ,
4235 \Magento \Framework \App \ActionFlag $ actionFlag ,
4336 \Magento \Store \Model \StoreManagerInterface $ storeManager ,
4437 \Noon \HideDefaultStoreCode \Helper \Data $ helper ,
4538 \Magento \Framework \UrlInterface $ url
4639 ) {
47- $ this ->redirect = $ redirect ;
4840 $ this ->actionFlag = $ actionFlag ;
4941 $ this ->storeManager = $ storeManager ;
5042 $ this ->helper = $ helper ;
@@ -65,11 +57,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
6557 $ url = $ this ->url ->getCurrentUrl ();
6658 $ pos = strpos ($ url , $ this ->storeManager ->getStore ()->getBaseUrl () . $ defaultStore ->getCode ());
6759
68- if ($ this ->helper ->isHideDefaultStoreCode () && $ pos !== false ) {
60+ if (
61+ $ this ->helper ->isHideDefaultStoreCode () &&
62+ $ pos !== false &&
63+ $ code = $ this ->helper ->getRedirectCode ()
64+ ) {
6965 $ controller = $ observer ->getData ('controller_action ' );
7066 $ url = str_replace ('/ ' . $ defaultStore ->getCode () . '/ ' , '/ ' , $ url );
7167 $ this ->actionFlag ->set ('' , \Magento \Framework \App \Action \Action::FLAG_NO_DISPATCH , true );
72- $ this -> redirect -> redirect ( $ controller ->getResponse (), $ url );
68+ $ controller ->getResponse ()-> setRedirect ( $ url , $ code );
7369 }
7470 }
7571 }
0 commit comments