diff --git a/app/code/Magento/Catalog/Block/Navigation.php b/app/code/Magento/Catalog/Block/Navigation.php index ed8f5d99d570064c34d8a0195b8865a6e8165f1e..77c1905eed71beb27c1bf1c1e72bc231ff98f5a5 100644 --- a/app/code/Magento/Catalog/Block/Navigation.php +++ b/app/code/Magento/Catalog/Block/Navigation.php @@ -173,16 +173,6 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Ma return $this->_currentCategoryKey; } - /** - * Get catagories of current store - * - * @return \Magento\Framework\Data\Tree\Node\Collection - */ - public function getStoreCategories() - { - return $this->_catalogCategory->getStoreCategories(); - } - /** * Retrieve child categories of current category * @@ -229,161 +219,6 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Ma return $url; } - /** - * Return item position representation in menu tree - * - * @param int $level - * @return string - */ - protected function _getItemPosition($level) - { - if ($level == 0) { - $zeroLevelPosition = isset( - $this->_itemLevelPositions[$level] - ) ? $this->_itemLevelPositions[$level] + 1 : 1; - $this->_itemLevelPositions = []; - $this->_itemLevelPositions[$level] = $zeroLevelPosition; - } elseif (isset($this->_itemLevelPositions[$level])) { - $this->_itemLevelPositions[$level]++; - } else { - $this->_itemLevelPositions[$level] = 1; - } - - $position = []; - for ($i = 0; $i <= $level; $i++) { - if (isset($this->_itemLevelPositions[$i])) { - $position[] = $this->_itemLevelPositions[$i]; - } - } - return implode('-', $position); - } - - /** - * Render category to html - * - * @param Category $category - * @param int $level Nesting level number - * @param boolean $isLast Whether ot not this item is last, affects list item class - * @param boolean $isFirst Whether ot not this item is first, affects list item class - * @param boolean $isOutermost Whether ot not this item is outermost, affects list item class - * @param string $outermostItemClass Extra class of outermost list items - * @param string $childrenWrapClass If specified wraps children list in div with this class - * @param boolean $noEventAttributes Whether ot not to add on* attributes to list item - * @return string - */ - protected function _renderCategoryMenuItemHtml( - $category, - $level = 0, - $isLast = false, - $isFirst = false, - $isOutermost = false, - $outermostItemClass = '', - $childrenWrapClass = '', - $noEventAttributes = false - ) { - if (!$category->getIsActive()) { - return ''; - } - - // get all children - if ($this->flatState->isAvailable()) { - $children = (array)$category->getChildrenNodes(); - } else { - $children = $category->getChildren(); - } - - // select active children - $activeChildren = []; - foreach ($children as $child) { - if ($child->getIsActive()) { - $activeChildren[] = $child; - } - } - - $activeChildrenCount = count($activeChildren); - $hasActiveChildren = $activeChildrenCount > 0; - - // prepare list item html classes - $classes = []; - $classes[] = 'level' . $level; - $classes[] = 'nav-' . $this->_getItemPosition($level); - if ($this->isCategoryActive($category)) { - $classes[] = 'active'; - } - - $linkClass = ''; - if ($isOutermost && $outermostItemClass) { - $classes[] = $outermostItemClass; - $linkClass = ' class="' . $outermostItemClass . '"'; - } - if ($isFirst) { - $classes[] = 'first'; - } - if ($isLast) { - $classes[] = 'last'; - } - if ($hasActiveChildren) { - $classes[] = 'parent'; - } - - // prepare list item attributes - $attributes = []; - if (count($classes) > 0) { - $attributes['class'] = implode(' ', $classes); - } - if ($hasActiveChildren && !$noEventAttributes) { - $attributes['onmouseover'] = 'toggleMenu(this,1)'; - $attributes['onmouseout'] = 'toggleMenu(this,0)'; - } - - // assemble list item with attributes - $htmlLi = '<li'; - foreach ($attributes as $attrName => $attrValue) { - $htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"'; - } - $htmlLi .= '>'; - - $html = []; - $html[] = $htmlLi; - - $html[] = '<a href="' . $this->getCategoryUrl($category) . '"' . $linkClass . '>'; - $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>'; - $html[] = '</a>'; - - // render children - $htmlChildren = ''; - $j = 0; - foreach ($activeChildren as $child) { - $htmlChildren .= $this->_renderCategoryMenuItemHtml( - $child, - $level + 1, - $j == $activeChildrenCount - 1, - $j == 0, - false, - $outermostItemClass, - $childrenWrapClass, - $noEventAttributes - ); - $j++; - } - if (!empty($htmlChildren)) { - if ($childrenWrapClass) { - $html[] = '<div class="' . $childrenWrapClass . '">'; - } - $html[] = '<ul class="level' . $level . '">'; - $html[] = $htmlChildren; - $html[] = '</ul>'; - if ($childrenWrapClass) { - $html[] = '</div>'; - } - } - - $html[] = '</li>'; - - $html = implode("\n", $html); - return $html; - } - /** * Enter description here... * @@ -394,107 +229,6 @@ class Navigation extends \Magento\Framework\View\Element\Template implements \Ma return $this->_catalogLayer->getCurrentCategory(); } - /** - * Enter description here... - * - * @return string - */ - public function getCurrentCategoryPath() - { - if ($this->getCurrentCategory()) { - return explode(',', $this->getCurrentCategory()->getPathInStore()); - } - return []; - } - - /** - * Enter description here... - * - * @param Category $category - * @return string - */ - public function drawOpenCategoryItem($category) - { - $html = ''; - if (!$category->getIsActive()) { - return $html; - } - - $html .= '<li'; - - if ($this->isCategoryActive($category)) { - $html .= ' class="active"'; - } - - $html .= '>' . "\n"; - $html .= '<a href="' . $this->getCategoryUrl( - $category - ) . '">' . '<span>' . $this->escapeHtml( - $category->getName() - ) . '</span></a>' . "\n"; - - if (in_array($category->getId(), $this->getCurrentCategoryPath())) { - $children = $category->getChildren(); - $hasChildren = $children && $children->count(); - - if ($hasChildren) { - $htmlChildren = ''; - foreach ($children as $child) { - $htmlChildren .= $this->drawOpenCategoryItem($child); - } - - if (!empty($htmlChildren)) { - $html .= '<ul>' . "\n" . $htmlChildren . '</ul>'; - } - } - } - $html .= '</li>' . "\n"; - - return $html; - } - - /** - * Render categories menu in HTML - * - * @param int $level Level number for list item class to start from - * @param string $outermostItemClass Extra class of outermost list items - * @param string $childrenWrapClass If specified wraps children list in div with this class - * @return string - */ - public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '') - { - $activeCategories = []; - foreach ($this->getStoreCategories() as $child) { - if ($child->getIsActive()) { - $activeCategories[] = $child; - } - } - $activeCategoriesCount = count($activeCategories); - $hasActiveCategoriesCount = $activeCategoriesCount > 0; - - if (!$hasActiveCategoriesCount) { - return ''; - } - - $html = ''; - $j = 0; - foreach ($activeCategories as $category) { - $html .= $this->_renderCategoryMenuItemHtml( - $category, - $level, - $j == $activeCategoriesCount - 1, - $j == 0, - true, - $outermostItemClass, - $childrenWrapClass, - true - ); - $j++; - } - - return $html; - } - /** * Return identifiers for produced content * diff --git a/app/code/Magento/Catalog/view/frontend/templates/navigation/top.phtml b/app/code/Magento/Catalog/view/frontend/templates/navigation/top.phtml deleted file mode 100644 index 5eed153ff318d6d837bb7d71f307e4770356904b..0000000000000000000000000000000000000000 --- a/app/code/Magento/Catalog/view/frontend/templates/navigation/top.phtml +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) - */ -?> -<?php -/** - * Top menu for store - * - * @var $this \Magento\Catalog\Block\Navigation - */ -?> -<?php -/** - * $this->renderCategoriesMenuHtml() supports optional arguments: - * int Level number for list item class to start from - * string Extra class of outermost list items - * string If specified wraps children list in div with this class - */ -?> -<?php $_menu = $this->renderCategoriesMenuHtml(0, 'level-top') ?> -<?php if ($_menu): ?> -<div class="nav container"> - <ul id="nav"> - <?php echo $_menu ?> - </ul> -</div> -<?php endif ?> diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index 485b7fd59268306cfad013b903526fb38c33e224..fa7d5001d208786259a3a92246fa715d6086df5e 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -328,6 +328,12 @@ return [ ['displayFullSummary', 'Magento\Tax\Model\Config'], ['displayZeroTax', 'Magento\Tax\Model\Config'], ['drawItem', 'Magento\Catalog\Block\Navigation'], + ['getStoreCategories', 'Magento\Catalog\Block\Navigation'], + ['_getItemPosition', 'Magento\Catalog\Block\Navigation'], + ['_renderCategoryMenuItemHtml', 'Magento\Catalog\Block\Navigation'], + ['getCurrentCategoryPath', 'Magento\Catalog\Block\Navigation'], + ['drawOpenCategoryItem', 'Magento\Catalog\Block\Navigation'], + ['renderCategoriesMenuHtml', 'Magento\Catalog\Block\Navigation'], ['dropKey', 'Magento\Framework\DB\Adapter\Pdo\Mysql'], ['escapeJs', 'Magento\Backend\Block\Catalog\Product\Edit\Tab\Super\Config'], ['eventClean', 'Magento\Reports\Model\Event\Observer'], diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Block/NavigationTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Block/NavigationTest.php index 5cd76891eab23509a1118bfce5c4447c921fc9bd..c65f75ec78c3b8b8992a56a95001d1da2998ec49 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Block/NavigationTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Block/NavigationTest.php @@ -14,16 +14,9 @@ class NavigationTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - $categoryFactory = $this->getMock( - 'Magento\Catalog\Model\CategoryFactory', - ['create'], - [], - '', - false - ); $this->block = $objectManager->getObject( 'Magento\Catalog\Block\Navigation', - ['categoryFactory' => $categoryFactory] + [] ); }