Skip to content

Commit 8f6bb18

Browse files
author
Michail Slabko
committed
MAGETWO-31647: 'You saved the category' message is present on new subcategory page
- MAGETWO-31723: Delete category message is absent after category has been deleted and a page has been loaded
1 parent 3bca5f4 commit 8f6bb18

File tree

5 files changed

+58
-24
lines changed
  • app/code/Magento/Catalog
  • dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Category

5 files changed

+58
-24
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function _prepareLayout()
9393
'onclick' => "categoryDelete('" . $this->getUrl(
9494
'catalog/*/delete',
9595
['_current' => true]
96-
) . "', true, {$categoryId})",
96+
) . "')",
9797
'class' => 'delete'
9898
]
9999
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public function execute()
1818
$resultRedirect = $this->resultRedirectFactory->create();
1919

2020
$categoryId = (int)$this->getRequest()->getParam('id');
21+
$parentId = null;
2122
if ($categoryId) {
2223
try {
2324
$category = $this->_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
25+
$parentId = $category->getParentId();
2426
$this->_eventManager->dispatch('catalog_controller_category_delete', ['category' => $category]);
25-
2627
$this->_objectManager->get('Magento\Backend\Model\Auth\Session')->setDeletedPath($category->getPath());
27-
2828
$category->delete();
2929
$this->messageManager->addSuccess(__('You deleted the category.'));
3030
} catch (\Magento\Framework\Model\Exception $e) {
@@ -35,6 +35,6 @@ public function execute()
3535
return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]);
3636
}
3737
}
38-
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
38+
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => $parentId]);
3939
}
4040
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function execute()
9797
. $resultPage->getLayout()->getBlock('category.tree')
9898
->getBreadcrumbsJavascript($breadcrumbsPath, 'editingCategoryBreadcrumbs'),
9999
'messages' => $resultPage->getLayout()->getMessagesBlock()->getGroupedHtml(),
100+
'toolbar' => $resultPage->getLayout()->getBlock('page.actions.toolbar')->toHtml()
100101
]);
101102
$this->_eventManager->dispatch(
102103
'category_prepare_ajax_response',

app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/edit.phtml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,16 @@ require([
3434
* This routine get categoryId explicitly, so even if currently selected tree node is out of sync
3535
* with this form, we surely delete same category in the tree and at backend
3636
*/
37-
function categoryDelete(url, useAjax, categoryId) {
37+
function categoryDelete(url) {
3838
if (confirm('<?php echo __('Are you sure you want to delete this category?') ?>')){
39-
if (useAjax){
40-
tree.nodeForDelete = categoryId;
41-
updateContent(url, {}, true, true);
42-
} else {
43-
location.href = url;
44-
}
39+
location.href = url;
4540
}
4641
}
4742

4843
/**
4944
* Update category content area
5045
*/
51-
function updateContent(url, params, refreshTree, deleteAction) {
46+
function updateContent(url, params, refreshTree) {
5247
var node = tree.getNodeById(tree.currentNodeId),
5348
parentNode = node && node.parentNode,
5449
parentId,
@@ -64,23 +59,15 @@ require([
6459
}
6560

6661
(function($){
67-
var $categoryContainer = $('#category-edit-container');
62+
var $categoryContainer = $('#category-edit-container'),
63+
messagesContainer = $('.messages');
64+
messagesContainer.html('');
6865
$.ajax({
6966
url: url + (url.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true' ),
7067
data: params,
7168
context: $('body'),
7269
showLoader: true
7370
}).done(function(data){
74-
if (deleteAction && parentNode) {
75-
parentId = parentNode.id;
76-
77-
redirectUrl = !parentNode.isRoot ?
78-
tree.buildUrl(parentId) :
79-
tree.getBaseUrl();
80-
81-
location.href = redirectUrl;
82-
}
83-
8471
if (data.content) {
8572
$('.page-actions').floatingHeader('destroy');
8673
try {
@@ -111,7 +98,10 @@ require([
11198
}
11299

113100
if (data.messages && data.messages.length > 0) {
114-
$('.messages').html(data.messages);
101+
messagesContainer.html(data.messages);
102+
}
103+
if (data.toolbar) {
104+
$('[data-ui-id="page-actions-toolbar-content-header"]').replaceWith(data.toolbar)
115105
}
116106
});
117107
})(jQuery);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
4+
*/
5+
namespace Magento\Catalog\Controller\Adminhtml\Category;
6+
7+
use Magento\Framework\Message\MessageInterface;
8+
9+
class DeleteTest extends \Magento\Backend\Utility\Controller
10+
{
11+
/**
12+
* @magentoDataFixture Magento/Catalog/_files/categories.php
13+
*/
14+
public function testDeleteById()
15+
{
16+
$categoryId = 4;
17+
$parentId = 3;
18+
$this->getRequest()->setParam('id', $categoryId);
19+
20+
$this->dispatch('backend/catalog/category/delete/');
21+
22+
$this->assertNull($this->getCategoryById($categoryId));
23+
$this->assertSessionMessages(
24+
$this->equalTo(['You deleted the category.']),
25+
MessageInterface::TYPE_SUCCESS
26+
);
27+
$this->assertRedirect($this->stringContains('catalog/category/index/id/' . $parentId));
28+
}
29+
30+
/**
31+
* Retrieve attribute set based on given name.
32+
*
33+
* @param int $categoryId
34+
* @return \Magento\Catalog\Model\Category|null
35+
*/
36+
protected function getCategoryById($categoryId)
37+
{
38+
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
39+
'Magento\Catalog\Model\Category'
40+
)->load($categoryId);
41+
return $category->getId() === null ? null : $category;
42+
}
43+
}

0 commit comments

Comments
 (0)