From a03c9ad8d1246737460b0b8b758adeb1cc73ce7b Mon Sep 17 00:00:00 2001 From: James Anelay Date: Mon, 9 Mar 2015 13:41:13 +0100 Subject: [PATCH 1/3] Move Topmenu CategoryData creation to a public method to enabled plugin additions --- app/code/Magento/Catalog/Model/Observer.php | 33 ++++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Observer.php b/app/code/Magento/Catalog/Model/Observer.php index dac92e427e266..e4a48721fcb0b 100644 --- a/app/code/Magento/Catalog/Model/Observer.php +++ b/app/code/Magento/Catalog/Model/Observer.php @@ -132,17 +132,12 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block continue; } - $nodeId = 'category-node-' . $category->getId(); - $block->addIdentity(\Magento\Catalog\Model\Category::CACHE_TAG . '_' . $category->getId()); $tree = $parentCategoryNode->getTree(); - $categoryData = [ - 'name' => $category->getName(), - 'id' => $nodeId, - 'url' => $this->_catalogCategory->getCategoryUrl($category), - 'is_active' => $this->_isActiveMenuCategory($category), - ]; + + $categoryData = $this->getMenuCategoryData($category); + $categoryNode = new \Magento\Framework\Data\Tree\Node($categoryData, 'id', $tree, $parentCategoryNode); $parentCategoryNode->addChild($categoryNode); @@ -156,6 +151,28 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block } } + + /** + * Get category data to be added to the Menu + * + * @param \Magento\Framework\Data\Tree\Node $category + * @return array + */ + public function getMenuCategoryData($category) + { + + $nodeId = 'category-node-' . $category->getId(); + + $categoryData = [ + 'name' => $category->getName(), + 'id' => $nodeId, + 'url' => $this->_catalogCategory->getCategoryUrl($category), + 'is_active' => $this->_isActiveMenuCategory($category), + ]; + + return $categoryData; + } + /** * Checks whether category belongs to active category's path * From b9fb63e6ddcc42c1e5102dbf9a49c180e73d7f9b Mon Sep 17 00:00:00 2001 From: James Anelay Date: Sat, 28 Mar 2015 00:23:42 +0000 Subject: [PATCH 2/3] getMenuCategoryData change scope to protected. I thought plugins had to be on public methods, turns out this is not the case so have set the method to protected. --- app/code/Magento/Catalog/Model/Observer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Observer.php b/app/code/Magento/Catalog/Model/Observer.php index e4a48721fcb0b..622cd3ce551dc 100644 --- a/app/code/Magento/Catalog/Model/Observer.php +++ b/app/code/Magento/Catalog/Model/Observer.php @@ -136,7 +136,7 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block $tree = $parentCategoryNode->getTree(); - $categoryData = $this->getMenuCategoryData($category); + $categoryData = $this->_getMenuCategoryData($category); $categoryNode = new \Magento\Framework\Data\Tree\Node($categoryData, 'id', $tree, $parentCategoryNode); $parentCategoryNode->addChild($categoryNode); @@ -158,7 +158,7 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block * @param \Magento\Framework\Data\Tree\Node $category * @return array */ - public function getMenuCategoryData($category) + protected function _getMenuCategoryData($category) { $nodeId = 'category-node-' . $category->getId(); From ebc103937938f858e1c9cbe24fafb50a1f898879 Mon Sep 17 00:00:00 2001 From: James Anelay Date: Mon, 30 Mar 2015 21:11:12 +0100 Subject: [PATCH 3/3] Revert "getMenuCategoryData change scope to protected." This reverts commit b9fb63e6ddcc42c1e5102dbf9a49c180e73d7f9b. --- app/code/Magento/Catalog/Model/Observer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Observer.php b/app/code/Magento/Catalog/Model/Observer.php index 622cd3ce551dc..e4a48721fcb0b 100644 --- a/app/code/Magento/Catalog/Model/Observer.php +++ b/app/code/Magento/Catalog/Model/Observer.php @@ -136,7 +136,7 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block $tree = $parentCategoryNode->getTree(); - $categoryData = $this->_getMenuCategoryData($category); + $categoryData = $this->getMenuCategoryData($category); $categoryNode = new \Magento\Framework\Data\Tree\Node($categoryData, 'id', $tree, $parentCategoryNode); $parentCategoryNode->addChild($categoryNode); @@ -158,7 +158,7 @@ protected function _addCategoriesToMenu($categories, $parentCategoryNode, $block * @param \Magento\Framework\Data\Tree\Node $category * @return array */ - protected function _getMenuCategoryData($category) + public function getMenuCategoryData($category) { $nodeId = 'category-node-' . $category->getId();