Skip to content

Commit aa72c97

Browse files
committed
MAGETWO-90940: SEO-friendly URL for category page not working
1 parent baf0561 commit aa72c97

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category.php

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@
88
namespace Magento\Catalog\Controller\Adminhtml;
99

1010
use Magento\Store\Model\Store;
11+
use Magento\Backend\App\Action\Context;
12+
use Magento\Framework\Stdlib\DateTime\Filter\Date;
13+
use Magento\Catalog\Model\Category as CategoryModel;
14+
use Magento\Backend\App\Action;
15+
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Framework\Registry;
17+
use Magento\Cms\Model\Wysiwyg\Config;
18+
use Magento\Backend\Model\View\Result\Page;
19+
use Magento\Framework\Controller\Result\Json;
20+
use Magento\Backend\Model\Auth\Session;
21+
use Magento\Framework\DataObject;
22+
use Zend_Filter_Input;
1123

1224
/**
1325
* Catalog category controller
1426
*/
15-
abstract class Category extends \Magento\Backend\App\Action
27+
abstract class Category extends Action
1628
{
1729
/**
1830
* Authorization level of a basic admin session
@@ -22,17 +34,17 @@ abstract class Category extends \Magento\Backend\App\Action
2234
const ADMIN_RESOURCE = 'Magento_Catalog::categories';
2335

2436
/**
25-
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
37+
* @var Date
2638
*/
2739
protected $dateFilter;
2840

2941
/**
30-
* @param \Magento\Backend\App\Action\Context $context
31-
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date|null $dateFilter
42+
* @param Context $context
43+
* @param Date|null $dateFilter
3244
*/
3345
public function __construct(
34-
\Magento\Backend\App\Action\Context $context,
35-
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter = null
46+
Context $context,
47+
Date $dateFilter = null
3648
) {
3749
$this->dateFilter = $dateFilter;
3850
parent::__construct($context);
@@ -43,20 +55,20 @@ public function __construct(
4355
* Root category can be returned, if inappropriate store/category is specified
4456
*
4557
* @param bool $getRootInstead
46-
* @return \Magento\Catalog\Model\Category|false
58+
* @return CategoryModel|false
4759
*/
4860
protected function _initCategory(bool $getRootInstead = false)
4961
{
5062
$categoryId = $this->resolveCategoryId();
5163
$storeId = $this->resolveStoreId();
52-
$category = $this->_objectManager->create(\Magento\Catalog\Model\Category::class);
64+
$category = $this->_objectManager->create(CategoryModel::class);
5365
$category->setStoreId($storeId);
5466

5567
if ($categoryId) {
5668
$category->load($categoryId);
5769
if ($storeId) {
5870
$rootId = $this->_objectManager->get(
59-
\Magento\Store\Model\StoreManagerInterface::class
71+
StoreManagerInterface::class
6072
)->getStore(
6173
$storeId
6274
)->getRootCategoryId();
@@ -71,9 +83,9 @@ protected function _initCategory(bool $getRootInstead = false)
7183
}
7284
}
7385

74-
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('category', $category);
75-
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('current_category', $category);
76-
$this->_objectManager->get(\Magento\Cms\Model\Wysiwyg\Config::class)
86+
$this->_objectManager->get(Registry::class)->register('category', $category);
87+
$this->_objectManager->get(Registry::class)->register('current_category', $category);
88+
$this->_objectManager->get(Config::class)
7789
->setStoreId($this->getRequest()->getParam('store'));
7890
return $category;
7991
}
@@ -105,26 +117,26 @@ private function resolveStoreId(): int
105117
return $storeId ?: (int)$this->getRequest()->getParam('store_id', Store::DEFAULT_STORE_ID);
106118
}
107119

108-
/**
120+
/**Zend_Filter_Input
109121
* Build response for ajax request
110122
*
111-
* @param \Magento\Catalog\Model\Category $category
112-
* @param \Magento\Backend\Model\View\Result\Page $resultPage
123+
* @param CategoryModel $category
124+
* @param Page $resultPage
113125
*
114-
* @return \Magento\Framework\Controller\Result\Json
126+
* @return Json
115127
*
116128
* @deprecated 101.0.0
117129
*/
118130
protected function ajaxRequestResponse(
119-
\Magento\Catalog\Model\Category $category,
120-
\Magento\Backend\Model\View\Result\Page $resultPage
121-
): \Magento\Framework\Controller\Result\Json {
131+
CategoryModel $category,
132+
Page $resultPage
133+
): Json {
122134
// prepare breadcrumbs of selected category, if any
123135
$breadcrumbsPath = $category->getPath();
124136
if (empty($breadcrumbsPath)) {
125137
// but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
126138
$breadcrumbsPath = $this->_objectManager->get(
127-
\Magento\Backend\Model\Auth\Session::class
139+
Session::class
128140
)->getDeletedPath(
129141
true
130142
);
@@ -140,7 +152,7 @@ protected function ajaxRequestResponse(
140152
}
141153
}
142154

143-
$eventResponse = new \Magento\Framework\DataObject([
155+
$eventResponse = new DataObject([
144156
'content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml()
145157
. $resultPage->getLayout()->getBlock('category.tree')
146158
->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'),
@@ -151,8 +163,8 @@ protected function ajaxRequestResponse(
151163
'category_prepare_ajax_response',
152164
['response' => $eventResponse, 'controller' => $this]
153165
);
154-
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
155-
$resultJson = $this->_objectManager->get(\Magento\Framework\Controller\Result\Json::class);
166+
/** @var Json $resultJson */
167+
$resultJson = $this->_objectManager->get(Json::class);
156168
$resultJson->setHeader('Content-type', 'application/json', true);
157169
$resultJson->setData($eventResponse->getData());
158170
return $resultJson;
@@ -161,12 +173,12 @@ protected function ajaxRequestResponse(
161173
/**
162174
* Datetime data preprocessing
163175
*
164-
* @param \Magento\Catalog\Model\Category $category
176+
* @param CategoryModel $category
165177
* @param array $postData
166178
*
167179
* @return array
168180
*/
169-
protected function dateTimePreprocessing(\Magento\Catalog\Model\Category $category, array $postData): array
181+
protected function dateTimePreprocessing(CategoryModel $category, array $postData): array
170182
{
171183
$dateFieldFilters = [];
172184
$attributes = $category->getAttributes();
@@ -177,7 +189,7 @@ protected function dateTimePreprocessing(\Magento\Catalog\Model\Category $catego
177189
}
178190
}
179191
}
180-
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $postData);
192+
$inputFilter = new Zend_Filter_Input($dateFieldFilters, [], $postData);
181193
return $inputFilter->getUnescaped();
182194
}
183195
}

0 commit comments

Comments
 (0)