Skip to content

Commit 1270d77

Browse files
Michail Slabkoorlangur
authored andcommitted
MAGETWO-31001: [GoInc] Improve Change Risk Analysis and Predictions Metric
- MAGETWO-31970: Magento\Catalog\Block\Navigation::_renderCategoryMenuItemHtml
1 parent ef48e5a commit 1270d77

File tree

4 files changed

+7
-302
lines changed

4 files changed

+7
-302
lines changed

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/view/frontend/templates/navigation/top.phtml

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

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@
328328
['displayFullSummary', 'Magento\Tax\Model\Config'],
329329
['displayZeroTax', 'Magento\Tax\Model\Config'],
330330
['drawItem', 'Magento\Catalog\Block\Navigation'],
331+
['getStoreCategories', 'Magento\Catalog\Block\Navigation'],
332+
['_getItemPosition', 'Magento\Catalog\Block\Navigation'],
333+
['_renderCategoryMenuItemHtml', 'Magento\Catalog\Block\Navigation'],
334+
['getCurrentCategoryPath', 'Magento\Catalog\Block\Navigation'],
335+
['drawOpenCategoryItem', 'Magento\Catalog\Block\Navigation'],
336+
['renderCategoriesMenuHtml', 'Magento\Catalog\Block\Navigation'],
331337
['dropKey', 'Magento\Framework\DB\Adapter\Pdo\Mysql'],
332338
['escapeJs', 'Magento\Backend\Block\Catalog\Product\Edit\Tab\Super\Config'],
333339
['eventClean', 'Magento\Reports\Model\Event\Observer'],

dev/tests/unit/testsuite/Magento/Catalog/Block/NavigationTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,9 @@ class NavigationTest extends \PHPUnit_Framework_TestCase
1414
protected function setUp()
1515
{
1616
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
17-
$categoryFactory = $this->getMock(
18-
'Magento\Catalog\Model\CategoryFactory',
19-
['create'],
20-
[],
21-
'',
22-
false
23-
);
2417
$this->block = $objectManager->getObject(
2518
'Magento\Catalog\Block\Navigation',
26-
['categoryFactory' => $categoryFactory]
19+
[]
2720
);
2821
}
2922

0 commit comments

Comments
 (0)