Skip to content

Commit 4ba2a1b

Browse files
authored
Merge pull request #584 from magefan/11205-Automatic-Redirects-Issue
11205-Automatic-Redirects-Issue
2 parents c4d658d + a041994 commit 4ba2a1b

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Controller/Category/View.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ class View extends \Magefan\Blog\App\Action\Action
2020
protected $_storeManager;
2121

2222
/**
23+
* @var \Magefan\Blog\Model\Url
24+
*/
25+
protected $url;
26+
27+
/**
28+
* View constructor.
2329
* @param \Magento\Framework\App\Action\Context $context
2430
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
31+
* @param \Magefan\Blog\Model\Url|null $url
2532
*/
2633
public function __construct(
2734
\Magento\Framework\App\Action\Context $context,
28-
\Magento\Store\Model\StoreManagerInterface $storeManager
35+
\Magento\Store\Model\StoreManagerInterface $storeManager,
36+
\Magefan\Blog\Model\Url $url = null
2937
) {
3038
parent::__construct($context);
3139
$this->_storeManager = $storeManager;
40+
$this->url = $url ?: $this->_objectManager->get(\Magefan\Blog\Model\Url::class);
3241
}
3342

3443
/**
@@ -43,8 +52,12 @@ public function execute()
4352
}
4453

4554
$category = $this->_initCategory();
55+
4656
if (!$category) {
47-
return $this->_forwardNoroute();
57+
$resultRedirect = $this->resultRedirectFactory->create();
58+
$resultRedirect->setHttpResponseCode(301);
59+
$resultRedirect->setPath($this->url->getBaseUrl());
60+
return $resultRedirect;
4861
}
4962

5063
$this->_objectManager->get(\Magento\Framework\Registry::class)

0 commit comments

Comments
 (0)