Skip to content

Commit 3595928

Browse files
committed
Remove active category in the cache key
- Remove setting of active related classes in ViewModel layer as they are now defined on JS side;
1 parent 7bed644 commit 3595928

File tree

2 files changed

+5
-55
lines changed

2 files changed

+5
-55
lines changed

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use Magento\Framework\Data\Tree\Node;
1313

1414
/**
15-
* Plugin for top menu block
15+
* Plugin that enhances the top menu block by building and managing the category tree
16+
* for menu rendering in a storefront.
1617
*/
1718
class Topmenu
1819
{
@@ -78,7 +79,6 @@ public function beforeGetHtml(
7879
$storeId = $this->storeManager->getStore()->getId();
7980
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
8081
$collection = $this->getCategoryTree($storeId, $rootId);
81-
$currentCategory = $this->getCurrentCategory();
8282
$mapping = [$rootId => $subject->getMenu()]; // use nodes stack to avoid recursion
8383
foreach ($collection as $category) {
8484
$categoryParentId = $category->getParentId();
@@ -95,11 +95,7 @@ public function beforeGetHtml(
9595
$parentCategoryNode = $mapping[$categoryParentId];
9696

9797
$categoryNode = new Node(
98-
$this->getCategoryAsArray(
99-
$category,
100-
$currentCategory,
101-
$category->getParentId() == $categoryParentId
102-
),
98+
$this->getCategoryAsArray($category),
10399
'id',
104100
$parentCategoryNode->getTree(),
105101
$parentCategoryNode
@@ -132,41 +128,20 @@ public function beforeGetIdentities(\Magento\Theme\Block\Html\Topmenu $subject)
132128
}
133129
}
134130

135-
/**
136-
* Get current Category from catalog layer
137-
*
138-
* @return \Magento\Catalog\Model\Category
139-
*/
140-
private function getCurrentCategory()
141-
{
142-
$catalogLayer = $this->layerResolver->get();
143-
144-
if (!$catalogLayer) {
145-
return null;
146-
}
147-
148-
return $catalogLayer->getCurrentCategory();
149-
}
150-
151131
/**
152132
* Convert category to array
153133
*
154134
* @param \Magento\Catalog\Model\Category $category
155-
* @param \Magento\Catalog\Model\Category $currentCategory
156-
* @param bool $isParentActive
157135
* @return array
158136
*/
159-
private function getCategoryAsArray($category, $currentCategory, $isParentActive)
137+
private function getCategoryAsArray($category)
160138
{
161139
$categoryId = $category->getId();
162140
return [
163141
'name' => $category->getName(),
164142
'id' => 'category-node-' . $categoryId,
165143
'url' => $this->catalogCategory->getCategoryUrl($category),
166-
'has_active' => in_array((string)$categoryId, explode('/', (string)$currentCategory->getPath()), true),
167-
'is_active' => $categoryId == $currentCategory->getId(),
168-
'is_category' => true,
169-
'is_parent_active' => $isParentActive
144+
'is_category' => true
170145
];
171146
}
172147

app/code/Magento/Theme/Block/Html/Topmenu.php

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

88
use Magento\Backend\Model\Menu;
99
use Magento\Framework\Data\Tree\Node;
10-
use Magento\Framework\Data\Tree\Node\Collection;
1110
use Magento\Framework\Data\Tree\NodeFactory;
1211
use Magento\Framework\Data\TreeFactory;
1312
use Magento\Framework\DataObject;
@@ -218,7 +217,6 @@ protected function _getHtml(
218217

219218
$children = $menuTree->getChildren();
220219
$childLevel = $this->getChildLevel($menuTree->getLevel());
221-
$this->removeChildrenWithoutActiveParent($children, $childLevel);
222220

223221
$counter = 1;
224222
$childrenCount = $children->count();
@@ -312,12 +310,6 @@ protected function _getMenuItemClasses(Node $item)
312310
$classes[] = 'first';
313311
}
314312

315-
if ($item->getIsActive()) {
316-
$classes[] = 'active';
317-
} elseif ($item->getHasActive()) {
318-
$classes[] = 'has-active';
319-
}
320-
321313
if ($item->getIsLast()) {
322314
$classes[] = 'last';
323315
}
@@ -379,23 +371,6 @@ public function getMenu()
379371
return $this->_menu;
380372
}
381373

382-
/**
383-
* Remove children from collection when the parent is not active
384-
*
385-
* @param Collection $children
386-
* @param int $childLevel
387-
* @return void
388-
*/
389-
private function removeChildrenWithoutActiveParent(Collection $children, int $childLevel): void
390-
{
391-
/** @var Node $child */
392-
foreach ($children as $child) {
393-
if ($childLevel === 0 && $child->getData('is_parent_active') === false) {
394-
$children->delete($child);
395-
}
396-
}
397-
}
398-
399374
/**
400375
* Retrieve child level based on parent level
401376
*

0 commit comments

Comments
 (0)