Skip to content

Commit 1b9c43a

Browse files
committed
Merge branch 'MAGETWO-49205' into switcher_stable
2 parents 18518e6 + bff77b4 commit 1b9c43a

File tree

21 files changed

+282
-198
lines changed

21 files changed

+282
-198
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Tree.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313

1414
use Magento\Catalog\Model\ResourceModel\Category\Collection;
1515
use Magento\Framework\Data\Tree\Node;
16+
use Magento\Store\Model\Store;
1617

18+
/**
19+
* Class Tree
20+
*
21+
* @package Magento\Catalog\Block\Adminhtml\Category
22+
*
23+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24+
*/
1725
class Tree extends \Magento\Catalog\Block\Adminhtml\Category\AbstractCategory
1826
{
1927
/**
@@ -76,31 +84,32 @@ protected function _construct()
7684
*/
7785
protected function _prepareLayout()
7886
{
79-
$addUrl = $this->getUrl("*/*/add", ['_current' => true, 'id' => null, '_query' => false]);
80-
81-
$this->addChild(
82-
'add_sub_button',
83-
'Magento\Backend\Block\Widget\Button',
84-
[
85-
'label' => __('Add Subcategory'),
86-
'onclick' => "addNew('" . $addUrl . "', false)",
87-
'class' => 'add',
88-
'id' => 'add_subcategory_button',
89-
'style' => $this->canAddSubCategory() ? '' : 'display: none;'
90-
]
91-
);
92-
93-
if ($this->canAddRootCategory()) {
87+
$addUrl = $this->getUrl("*/*/add", ['_current' => false, 'id' => null, '_query' => false]);
88+
if ($this->getStore()->getId() == Store::DEFAULT_STORE_ID) {
9489
$this->addChild(
95-
'add_root_button',
90+
'add_sub_button',
9691
'Magento\Backend\Block\Widget\Button',
9792
[
98-
'label' => __('Add Root Category'),
99-
'onclick' => "addNew('" . $addUrl . "', true)",
93+
'label' => __('Add Subcategory'),
94+
'onclick' => "addNew('" . $addUrl . "', false)",
10095
'class' => 'add',
101-
'id' => 'add_root_category_button'
96+
'id' => 'add_subcategory_button',
97+
'style' => $this->canAddSubCategory() ? '' : 'display: none;'
10298
]
10399
);
100+
101+
if ($this->canAddRootCategory()) {
102+
$this->addChild(
103+
'add_root_button',
104+
'Magento\Backend\Block\Widget\Button',
105+
[
106+
'label' => __('Add Root Category'),
107+
'onclick' => "addNew('" . $addUrl . "', true)",
108+
'class' => 'add',
109+
'id' => 'add_root_category_button'
110+
]
111+
);
112+
}
104113
}
105114

106115
return parent::_prepareLayout();

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,55 @@ protected function _initCategory($getRootInstead = false)
5656
->setStoreId($this->getRequest()->getParam('store'));
5757
return $category;
5858
}
59+
60+
/**
61+
* Build response for ajax request
62+
*
63+
* @param \Magento\Catalog\Model\Category $category
64+
* @param \Magento\Backend\Model\View\Result\Page $resultPage
65+
*
66+
* @return \Magento\Framework\Controller\Result\Json
67+
*
68+
* @deprecated
69+
*/
70+
protected function ajaxRequestResponse($category, $resultPage)
71+
{
72+
// prepare breadcrumbs of selected category, if any
73+
$breadcrumbsPath = $category->getPath();
74+
if (empty($breadcrumbsPath)) {
75+
// but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
76+
$breadcrumbsPath = $this->_objectManager->get(
77+
'Magento\Backend\Model\Auth\Session'
78+
)->getDeletedPath(
79+
true
80+
);
81+
if (!empty($breadcrumbsPath)) {
82+
$breadcrumbsPath = explode('/', $breadcrumbsPath);
83+
// no need to get parent breadcrumbs if deleting category level 1
84+
if (count($breadcrumbsPath) <= 1) {
85+
$breadcrumbsPath = '';
86+
} else {
87+
array_pop($breadcrumbsPath);
88+
$breadcrumbsPath = implode('/', $breadcrumbsPath);
89+
}
90+
}
91+
}
92+
93+
$eventResponse = new \Magento\Framework\DataObject([
94+
'content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml()
95+
. $resultPage->getLayout()->getBlock('category.tree')
96+
->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'),
97+
'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(),
98+
'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()
99+
]);
100+
$this->_eventManager->dispatch(
101+
'category_prepare_ajax_response',
102+
['response' => $eventResponse, 'controller' => $this]
103+
);
104+
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
105+
$resultJson = $this->_objectManager->get('Magento\Framework\Controller\Result\Json');
106+
$resultJson->setHeader('Content-type', 'application/json', true);
107+
$resultJson->setData($eventResponse->getData());
108+
return $resultJson;
109+
}
59110
}

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@
66
*/
77
namespace Magento\Catalog\Controller\Adminhtml\Category;
88

9+
/**
10+
* Class Add Category
11+
*
12+
* @package Magento\Catalog\Controller\Adminhtml\Category
13+
*/
914
class Add extends \Magento\Catalog\Controller\Adminhtml\Category
1015
{
1116
/**
17+
* Forward factory for result
18+
*
1219
* @var \Magento\Backend\Model\View\Result\ForwardFactory
1320
*/
1421
protected $resultForwardFactory;
1522

1623
/**
24+
* Add category constructor
25+
*
1726
* @param \Magento\Backend\App\Action\Context $context
1827
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
1928
*/
@@ -32,8 +41,32 @@ public function __construct(
3241
*/
3342
public function execute()
3443
{
35-
/** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
36-
$resultForward = $this->resultForwardFactory->create();
37-
return $resultForward->forward('edit');
44+
$parentId = (int)$this->getRequest()->getParam('parent');
45+
46+
$category = $this->_initCategory(true);
47+
if (!$category || !$parentId || $category->getId()) {
48+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
49+
$resultRedirect = $this->resultRedirectFactory->create();
50+
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
51+
}
52+
53+
$resultPageFactory = $this->_objectManager->get('Magento\Framework\View\Result\PageFactory');
54+
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
55+
$resultPage = $resultPageFactory->create();
56+
57+
if ($this->getRequest()->getQuery('isAjax')) {
58+
return $this->ajaxRequestResponse($category, $resultPage);
59+
}
60+
61+
$resultPage->setActiveMenu('Magento_Catalog::catalog_categories');
62+
$resultPage->getConfig()->getTitle()->prepend(__('New Category'));
63+
$resultPage->addBreadcrumb(__('Manage Catalog Categories'), __('Manage Categories'));
64+
65+
$block = $resultPage->getLayout()->getBlock('catalog.wysiwyg.js');
66+
if ($block) {
67+
$block->setStoreId(0);
68+
}
69+
70+
return $resultPage;
3871
}
3972
}

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

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ public function __construct(
5252
public function execute()
5353
{
5454
$storeId = (int)$this->getRequest()->getParam('store');
55-
$parentId = (int)$this->getRequest()->getParam('parent');
5655
$categoryId = (int)$this->getRequest()->getParam('id');
5756

58-
if (!$categoryId && !$parentId) {
57+
if (!$categoryId) {
5958
if ($storeId) {
6059
$categoryId = (int)$this->storeManager->getStore($storeId)->getRootCategoryId();
6160
} else {
@@ -74,7 +73,7 @@ public function execute()
7473
}
7574

7675
$category = $this->_initCategory(true);
77-
if (!$category) {
76+
if (!$category || $categoryId != $category->getId() || !$category->getId()) {
7877
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
7978
$resultRedirect = $this->resultRedirectFactory->create();
8079
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
@@ -90,47 +89,9 @@ public function execute()
9089

9190
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
9291
$resultPage = $this->resultPageFactory->create();
93-
/**
94-
* Build response for ajax request
95-
*/
96-
if ($this->getRequest()->getQuery('isAjax')) {
97-
// prepare breadcrumbs of selected category, if any
98-
$breadcrumbsPath = $category->getPath();
99-
if (empty($breadcrumbsPath)) {
100-
// but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
101-
$breadcrumbsPath = $this->_objectManager->get(
102-
'Magento\Backend\Model\Auth\Session'
103-
)->getDeletedPath(
104-
true
105-
);
106-
if (!empty($breadcrumbsPath)) {
107-
$breadcrumbsPath = explode('/', $breadcrumbsPath);
108-
// no need to get parent breadcrumbs if deleting category level 1
109-
if (count($breadcrumbsPath) <= 1) {
110-
$breadcrumbsPath = '';
111-
} else {
112-
array_pop($breadcrumbsPath);
113-
$breadcrumbsPath = implode('/', $breadcrumbsPath);
114-
}
115-
}
116-
}
11792

118-
$eventResponse = new \Magento\Framework\DataObject([
119-
'content' => $resultPage->getLayout()->getUiComponent('category_form')->getFormHtml()
120-
. $resultPage->getLayout()->getBlock('category.tree')
121-
->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'),
122-
'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(),
123-
'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()
124-
]);
125-
$this->_eventManager->dispatch(
126-
'category_prepare_ajax_response',
127-
['response' => $eventResponse, 'controller' => $this]
128-
);
129-
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
130-
$resultJson = $this->resultJsonFactory->create();
131-
$resultJson->setHeader('Content-type', 'application/json', true);
132-
$resultJson->setData($eventResponse->getData());
133-
return $resultJson;
93+
if ($this->getRequest()->getQuery('isAjax')) {
94+
return $this->ajaxRequestResponse($category, $resultPage);
13495
}
13596

13697
$resultPage->setActiveMenu('Magento_Catalog::catalog_categories');

app/code/Magento/Catalog/Model/Indexer/Category/Product/Plugin/IndexerState.php

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Category/EditTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,10 @@ public function testExecute($categoryId, $storeId)
284284
->with('id', $categoryId)
285285
->will($this->returnValue(true));
286286

287+
$this->categoryMock->expects($this->atLeastOnce())
288+
->method('getId')
289+
->will($this->returnValue($categoryId));
290+
287291
/**
288292
* @var \Magento\Framework\View\Element\Template
289293
* |\PHPUnit_Framework_MockObject_MockObject $blockMock

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Category/Product/Plugin/IndexerStateTest.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

app/code/Magento/Catalog/etc/di.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,9 @@
4646
<type name="Magento\Customer\Model\ResourceModel\Visitor">
4747
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
4848
</type>
49-
<type name="Magento\Indexer\Model\Indexer\State">
50-
<plugin name="setStatusForIndexer" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\IndexerState" />
51-
</type>
5249
<type name="Magento\Framework\Mview\View\StateInterface">
5350
<plugin name="setStatusForMview" type="Magento\Catalog\Model\Indexer\Category\Product\Plugin\MviewState" />
5451
</type>
55-
<type name="Magento\Catalog\Model\Indexer\Category\Product\Plugin\IndexerState">
56-
<arguments>
57-
<argument name="state" xsi:type="object" shared="false">Magento\Indexer\Model\Indexer\State</argument>
58-
</arguments>
59-
</type>
6052
<type name="Magento\Catalog\Model\Indexer\Category\Product\Plugin\MviewState">
6153
<arguments>
6254
<argument name="state" xsi:type="object" shared="false">Magento\Framework\Mview\View\StateInterface</argument>

0 commit comments

Comments
 (0)