Skip to content

Commit 4ce64b6

Browse files
committed
Merge pull request #18 from magento-goinc/MAGETWO-32346
[GoInc] Bug Fixes & Improve Change Risk Analysis and Predictions Metric
2 parents 9c19d10 + a55bb3e commit 4ce64b6

File tree

17 files changed

+521
-484
lines changed

17 files changed

+521
-484
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/Block/Navigation.php

Lines changed: 0 additions & 266 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,6 @@ public function getCurrenCategoryKey()
173173
return $this->_currentCategoryKey;
174174
}
175175

176-
/**
177-
* Get catagories of current store
178-
*
179-
* @return \Magento\Framework\Data\Tree\Node\Collection
180-
*/
181-
public function getStoreCategories()
182-
{
183-
return $this->_catalogCategory->getStoreCategories();
184-
}
185-
186176
/**
187177
* Retrieve child categories of current category
188178
*
@@ -229,161 +219,6 @@ public function getCategoryUrl($category)
229219
return $url;
230220
}
231221

232-
/**
233-
* Return item position representation in menu tree
234-
*
235-
* @param int $level
236-
* @return string
237-
*/
238-
protected function _getItemPosition($level)
239-
{
240-
if ($level == 0) {
241-
$zeroLevelPosition = isset(
242-
$this->_itemLevelPositions[$level]
243-
) ? $this->_itemLevelPositions[$level] + 1 : 1;
244-
$this->_itemLevelPositions = [];
245-
$this->_itemLevelPositions[$level] = $zeroLevelPosition;
246-
} elseif (isset($this->_itemLevelPositions[$level])) {
247-
$this->_itemLevelPositions[$level]++;
248-
} else {
249-
$this->_itemLevelPositions[$level] = 1;
250-
}
251-
252-
$position = [];
253-
for ($i = 0; $i <= $level; $i++) {
254-
if (isset($this->_itemLevelPositions[$i])) {
255-
$position[] = $this->_itemLevelPositions[$i];
256-
}
257-
}
258-
return implode('-', $position);
259-
}
260-
261-
/**
262-
* Render category to html
263-
*
264-
* @param Category $category
265-
* @param int $level Nesting level number
266-
* @param boolean $isLast Whether ot not this item is last, affects list item class
267-
* @param boolean $isFirst Whether ot not this item is first, affects list item class
268-
* @param boolean $isOutermost Whether ot not this item is outermost, affects list item class
269-
* @param string $outermostItemClass Extra class of outermost list items
270-
* @param string $childrenWrapClass If specified wraps children list in div with this class
271-
* @param boolean $noEventAttributes Whether ot not to add on* attributes to list item
272-
* @return string
273-
*/
274-
protected function _renderCategoryMenuItemHtml(
275-
$category,
276-
$level = 0,
277-
$isLast = false,
278-
$isFirst = false,
279-
$isOutermost = false,
280-
$outermostItemClass = '',
281-
$childrenWrapClass = '',
282-
$noEventAttributes = false
283-
) {
284-
if (!$category->getIsActive()) {
285-
return '';
286-
}
287-
288-
// get all children
289-
if ($this->flatState->isAvailable()) {
290-
$children = (array)$category->getChildrenNodes();
291-
} else {
292-
$children = $category->getChildren();
293-
}
294-
295-
// select active children
296-
$activeChildren = [];
297-
foreach ($children as $child) {
298-
if ($child->getIsActive()) {
299-
$activeChildren[] = $child;
300-
}
301-
}
302-
303-
$activeChildrenCount = count($activeChildren);
304-
$hasActiveChildren = $activeChildrenCount > 0;
305-
306-
// prepare list item html classes
307-
$classes = [];
308-
$classes[] = 'level' . $level;
309-
$classes[] = 'nav-' . $this->_getItemPosition($level);
310-
if ($this->isCategoryActive($category)) {
311-
$classes[] = 'active';
312-
}
313-
314-
$linkClass = '';
315-
if ($isOutermost && $outermostItemClass) {
316-
$classes[] = $outermostItemClass;
317-
$linkClass = ' class="' . $outermostItemClass . '"';
318-
}
319-
if ($isFirst) {
320-
$classes[] = 'first';
321-
}
322-
if ($isLast) {
323-
$classes[] = 'last';
324-
}
325-
if ($hasActiveChildren) {
326-
$classes[] = 'parent';
327-
}
328-
329-
// prepare list item attributes
330-
$attributes = [];
331-
if (count($classes) > 0) {
332-
$attributes['class'] = implode(' ', $classes);
333-
}
334-
if ($hasActiveChildren && !$noEventAttributes) {
335-
$attributes['onmouseover'] = 'toggleMenu(this,1)';
336-
$attributes['onmouseout'] = 'toggleMenu(this,0)';
337-
}
338-
339-
// assemble list item with attributes
340-
$htmlLi = '<li';
341-
foreach ($attributes as $attrName => $attrValue) {
342-
$htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
343-
}
344-
$htmlLi .= '>';
345-
346-
$html = [];
347-
$html[] = $htmlLi;
348-
349-
$html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>';
350-
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
351-
$html[] = '</a>';
352-
353-
// render children
354-
$htmlChildren = '';
355-
$j = 0;
356-
foreach ($activeChildren as $child) {
357-
$htmlChildren .= $this->_renderCategoryMenuItemHtml(
358-
$child,
359-
$level + 1,
360-
$j == $activeChildrenCount - 1,
361-
$j == 0,
362-
false,
363-
$outermostItemClass,
364-
$childrenWrapClass,
365-
$noEventAttributes
366-
);
367-
$j++;
368-
}
369-
if (!empty($htmlChildren)) {
370-
if ($childrenWrapClass) {
371-
$html[] = '<div class="' . $childrenWrapClass . '">';
372-
}
373-
$html[] = '<ul class="level' . $level . '">';
374-
$html[] = $htmlChildren;
375-
$html[] = '</ul>';
376-
if ($childrenWrapClass) {
377-
$html[] = '</div>';
378-
}
379-
}
380-
381-
$html[] = '</li>';
382-
383-
$html = implode("\n", $html);
384-
return $html;
385-
}
386-
387222
/**
388223
* Enter description here...
389224
*
@@ -394,107 +229,6 @@ public function getCurrentCategory()
394229
return $this->_catalogLayer->getCurrentCategory();
395230
}
396231

397-
/**
398-
* Enter description here...
399-
*
400-
* @return string
401-
*/
402-
public function getCurrentCategoryPath()
403-
{
404-
if ($this->getCurrentCategory()) {
405-
return explode(',', $this->getCurrentCategory()->getPathInStore());
406-
}
407-
return [];
408-
}
409-
410-
/**
411-
* Enter description here...
412-
*
413-
* @param Category $category
414-
* @return string
415-
*/
416-
public function drawOpenCategoryItem($category)
417-
{
418-
$html = '';
419-
if (!$category->getIsActive()) {
420-
return $html;
421-
}
422-
423-
$html .= '<li';
424-
425-
if ($this->isCategoryActive($category)) {
426-
$html .= ' class="active"';
427-
}
428-
429-
$html .= '>' . "\n";
430-
$html .= '<a href="' . $this->getCategoryUrl(
431-
$category
432-
) . '">' . '<span>' . $this->escapeHtml(
433-
$category->getName()
434-
) . '</span></a>' . "\n";
435-
436-
if (in_array($category->getId(), $this->getCurrentCategoryPath())) {
437-
$children = $category->getChildren();
438-
$hasChildren = $children && $children->count();
439-
440-
if ($hasChildren) {
441-
$htmlChildren = '';
442-
foreach ($children as $child) {
443-
$htmlChildren .= $this->drawOpenCategoryItem($child);
444-
}
445-
446-
if (!empty($htmlChildren)) {
447-
$html .= '<ul>' . "\n" . $htmlChildren . '</ul>';
448-
}
449-
}
450-
}
451-
$html .= '</li>' . "\n";
452-
453-
return $html;
454-
}
455-
456-
/**
457-
* Render categories menu in HTML
458-
*
459-
* @param int $level Level number for list item class to start from
460-
* @param string $outermostItemClass Extra class of outermost list items
461-
* @param string $childrenWrapClass If specified wraps children list in div with this class
462-
* @return string
463-
*/
464-
public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
465-
{
466-
$activeCategories = [];
467-
foreach ($this->getStoreCategories() as $child) {
468-
if ($child->getIsActive()) {
469-
$activeCategories[] = $child;
470-
}
471-
}
472-
$activeCategoriesCount = count($activeCategories);
473-
$hasActiveCategoriesCount = $activeCategoriesCount > 0;
474-
475-
if (!$hasActiveCategoriesCount) {
476-
return '';
477-
}
478-
479-
$html = '';
480-
$j = 0;
481-
foreach ($activeCategories as $category) {
482-
$html .= $this->_renderCategoryMenuItemHtml(
483-
$category,
484-
$level,
485-
$j == $activeCategoriesCount - 1,
486-
$j == 0,
487-
true,
488-
$outermostItemClass,
489-
$childrenWrapClass,
490-
true
491-
);
492-
$j++;
493-
}
494-
495-
return $html;
496-
}
497-
498232
/**
499233
* Return identifiers for produced content
500234
*

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@
77

88
class Delete extends \Magento\Catalog\Controller\Adminhtml\Category
99
{
10+
/** @var \Magento\Catalog\Api\CategoryRepositoryInterface */
11+
protected $categoryRepository;
12+
13+
/**
14+
* @param \Magento\Backend\App\Action\Context $context
15+
* @param \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory
16+
* @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
17+
*/
18+
public function __construct(
19+
\Magento\Backend\App\Action\Context $context,
20+
\Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory,
21+
\Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
22+
) {
23+
parent::__construct($context, $resultRedirectFactory);
24+
$this->categoryRepository = $categoryRepository;
25+
}
26+
1027
/**
1128
* Delete category action
1229
*
@@ -18,14 +35,14 @@ public function execute()
1835
$resultRedirect = $this->resultRedirectFactory->create();
1936

2037
$categoryId = (int)$this->getRequest()->getParam('id');
38+
$parentId = null;
2139
if ($categoryId) {
2240
try {
23-
$category = $this->_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
41+
$category = $this->categoryRepository->get($categoryId);
42+
$parentId = $category->getParentId();
2443
$this->_eventManager->dispatch('catalog_controller_category_delete', ['category' => $category]);
25-
26-
$this->_objectManager->get('Magento\Backend\Model\Auth\Session')->setDeletedPath($category->getPath());
27-
28-
$category->delete();
44+
$this->_auth->getAuthStorage()->setDeletedPath($category->getPath());
45+
$this->categoryRepository->delete($category);
2946
$this->messageManager->addSuccess(__('You deleted the category.'));
3047
} catch (\Magento\Framework\Model\Exception $e) {
3148
$this->messageManager->addError($e->getMessage());
@@ -35,6 +52,6 @@ public function execute()
3552
return $resultRedirect->setPath('catalog/*/edit', ['_current' => true]);
3653
}
3754
}
38-
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
55+
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => $parentId]);
3956
}
4057
}

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',

0 commit comments

Comments
 (0)