Skip to content

Commit

Permalink
Move Topmenu CategoryData creation to a public method to enabled plug…
Browse files Browse the repository at this point in the history
…in additions
  • Loading branch information
JamesAnelay committed Mar 9, 2015
1 parent d0131d7 commit a03c9ad
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions app/code/Magento/Catalog/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
*
Expand Down

0 comments on commit a03c9ad

Please sign in to comment.