Skip to content

Commit d63b842

Browse files
authored
Merge branch '2.4-develop' into LYNX-311-DELIVERY
2 parents 116db32 + 9846306 commit d63b842

11 files changed

+1220
-114
lines changed

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

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
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
{
1920
/**
20-
* Catalog category
21-
*
2221
* @var \Magento\Catalog\Helper\Category
2322
*/
2423
protected $catalogCategory;
@@ -33,29 +32,21 @@ class Topmenu
3332
*/
3433
private $storeManager;
3534

36-
/**
37-
* @var \Magento\Catalog\Model\Layer\Resolver
38-
*/
39-
private $layerResolver;
40-
4135
/**
4236
* Initialize dependencies.
4337
*
4438
* @param \Magento\Catalog\Helper\Category $catalogCategory
4539
* @param \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory
4640
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
47-
* @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
4841
*/
4942
public function __construct(
5043
\Magento\Catalog\Helper\Category $catalogCategory,
5144
\Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory,
52-
\Magento\Store\Model\StoreManagerInterface $storeManager,
53-
\Magento\Catalog\Model\Layer\Resolver $layerResolver
45+
\Magento\Store\Model\StoreManagerInterface $storeManager
5446
) {
5547
$this->catalogCategory = $catalogCategory;
5648
$this->collectionFactory = $categoryCollectionFactory;
5749
$this->storeManager = $storeManager;
58-
$this->layerResolver = $layerResolver;
5950
}
6051

6152
/**
@@ -78,7 +69,6 @@ public function beforeGetHtml(
7869
$storeId = $this->storeManager->getStore()->getId();
7970
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $collection */
8071
$collection = $this->getCategoryTree($storeId, $rootId);
81-
$currentCategory = $this->getCurrentCategory();
8272
$mapping = [$rootId => $subject->getMenu()]; // use nodes stack to avoid recursion
8373
foreach ($collection as $category) {
8474
$categoryParentId = $category->getParentId();
@@ -97,7 +87,6 @@ public function beforeGetHtml(
9787
$categoryNode = new Node(
9888
$this->getCategoryAsArray(
9989
$category,
100-
$currentCategory,
10190
$category->getParentId() == $categoryParentId
10291
),
10392
'id',
@@ -132,39 +121,20 @@ public function beforeGetIdentities(\Magento\Theme\Block\Html\Topmenu $subject)
132121
}
133122
}
134123

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-
151124
/**
152125
* Convert category to array
153126
*
154-
* @param \Magento\Catalog\Model\Category $category
155-
* @param \Magento\Catalog\Model\Category $currentCategory
127+
* @param Category $category
156128
* @param bool $isParentActive
157129
* @return array
158130
*/
159-
private function getCategoryAsArray($category, $currentCategory, $isParentActive)
131+
private function getCategoryAsArray($category, $isParentActive): array
160132
{
161133
$categoryId = $category->getId();
162134
return [
163135
'name' => $category->getName(),
164136
'id' => 'category-node-' . $categoryId,
165137
'url' => $this->catalogCategory->getCategoryUrl($category),
166-
'has_active' => in_array((string)$categoryId, explode('/', (string)$currentCategory->getPath()), true),
167-
'is_active' => $categoryId == $currentCategory->getId(),
168138
'is_category' => true,
169139
'is_parent_active' => $isParentActive
170140
];
@@ -196,22 +166,4 @@ protected function getCategoryTree($storeId, $rootId)
196166

197167
return $collection;
198168
}
199-
200-
/**
201-
* Add active
202-
*
203-
* @param \Magento\Theme\Block\Html\Topmenu $subject
204-
* @param string[] $result
205-
* @return string[]
206-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
207-
*/
208-
public function afterGetCacheKeyInfo(\Magento\Theme\Block\Html\Topmenu $subject, array $result)
209-
{
210-
$activeCategory = $this->getCurrentCategory();
211-
if ($activeCategory) {
212-
$result[] = Category::CACHE_TAG . '_' . $activeCategory->getId();
213-
}
214-
215-
return $result;
216-
}
217169
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="EnableCategoriesPathForProductUrls">
12+
<data key="path">catalog/seo/product_use_categories</data>
13+
<data key="scope_id">0</data>
14+
<data key="label">Yes</data>
15+
<data key="value">1</data>
16+
</entity>
17+
<entity name="DisableCategoriesPathForProductUrls">
18+
<data key="path">catalog/seo/product_use_categories</data>
19+
<data key="scope_id">0</data>
20+
<data key="label">No</data>
21+
<data key="value">0</data>
22+
</entity>
23+
</entities>

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategorySidebarTreeSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
<element name="collapseAll" type="button" selector=".tree-actions a:first-child"/>
1313
<element name="expandAll" type="button" selector=".tree-actions a:last-child"/>
1414
<element name="categoryHighlighted" type="text" selector="//div[@id='store.menu']//span[contains(text(),'{{name}}')]/ancestor::li" parameterized="true" timeout="30"/>
15+
<element name="dynamicActiveClassSelector" type="text" selector="//div[@id='store.menu']//span[contains(text(),'{{name}}')]/ancestor::li[contains(@class, '{{containsClass}}') and not(contains(@class, '{{notContainsClass}}'))]" parameterized="true" timeout="30"/>
1516
<element name="categoryNotHighlighted" type="text" selector="[id=\'store.menu\'] ul li.active" timeout="30"/>
17+
<element name="parentCategoryNotHighlighted" type="text" selector="[id=\'store.menu\'] ul li.has-active" timeout="30"/>
1618
<element name="categoryTreeRoot" type="text" selector="li.x-tree-node:first-of-type > div.x-tree-node-el:first-of-type" timeout="30"/>
1719
<element name="categoryInTree" type="text" selector="//a[contains(text(), '{{name}}')]" parameterized="true" timeout="30"/>
1820
<element name="categoryInFrontendTree" type="text" selector="//a/span[contains(text(), '{{name}}')]" parameterized="true" timeout="30"/>

0 commit comments

Comments
 (0)