Skip to content

Commit 29f38a1

Browse files
committed
Merge branch 'ACP2E-3131' of https://github.com/adobe-commerce-tier-4/magento2ce into Tier4-09-12-2024
2 parents 30b974a + 024a648 commit 29f38a1

File tree

5 files changed

+111
-16
lines changed

5 files changed

+111
-16
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Widget/Chooser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function _getNodeJson($node, $level = 0)
152152
if (in_array($node->getId(), $this->getSelectedCategories())) {
153153
$item['checked'] = true;
154154
}
155-
$item['is_anchor'] = (int)$node->getIsAnchor();
155+
$item['is_anchor'] = $node->getIsAnchor() !== null ? (int) $node->getIsAnchor() : 1;
156156
$item['url_key'] = $node->getData('url_key');
157157
return $item;
158158
}

app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/widget/tree.phtml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ $scriptString = <<<script
1919
2020
require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
2121
22-
let tree = $('#tree{$block->escapeJs($block->getId())}');
22+
let tree = $('#tree{$escaper->escapeJs($block->getId())}');
2323
let useMassAction = {$isUseMassAction};
2424
let isAnchorOnly = {$isAnchorOnly};
25+
let isAnchorArr = [];
2526
let checkedNodes = [];
2627
2728
function addLastNodeProperty(nodes) {
@@ -38,10 +39,18 @@ require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
3839
const rootNode = tree.jstree().get_node("#");
3940
const rootId = rootNode.children[0];
4041
41-
if (isAnchorOnly === 1 && node.id === rootId) {
42-
tree.jstree(true).disable_node(node);
43-
} else if (isAnchorOnly === 0 && node.id !== rootId) {
44-
tree.jstree(true).disable_node(node);
42+
if (isAnchorOnly === 1) {
43+
if (1 === isAnchorArr[parseInt(node.id)]) {
44+
tree.jstree(true).enable_node(node);
45+
} else {
46+
tree.jstree(true).disable_node(node);
47+
}
48+
} else {
49+
if (0 === isAnchorArr[parseInt(node.id)]) {
50+
tree.jstree(true).enable_node(node);
51+
} else {
52+
tree.jstree(true).disable_node(node);
53+
}
4554
}
4655
});
4756
}
@@ -52,12 +61,7 @@ require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
5261
5362
data.instance.get_json('#', { flat: true }).forEach(nodeId => {
5463
const node = data.instance.get_node(nodeId);
55-
56-
if (checkedNodes.includes(node.id)) {
57-
tree.jstree(true).select_node(node.id);
58-
}
59-
60-
actionBasedOnIsAnchorOnly();
64+
getAnchorNodeIds(tree, node);
6165
});
6266
}
6367
@@ -106,6 +110,17 @@ require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
106110
}
107111
}
108112
113+
function getAnchorNodeIds(tree, node) {
114+
if (useMassAction) {
115+
isAnchorArr[parseInt(node.id)] = node.original.is_anchor;
116+
if (checkedNodes.includes(node.id)) {
117+
tree.jstree(true).select_node(node.id);
118+
}
119+
getCheckedNodeIds(tree, node);
120+
actionBasedOnIsAnchorOnly();
121+
}
122+
}
123+
109124
function handleSuccessResponse(response, childNode, data) {
110125
if (response.length > 0) {
111126
response.forEach(newNode => {
@@ -114,11 +129,9 @@ require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
114129
// Create the new node and execute node callback
115130
data.instance.create_node(childNode, newNode, 'last', node => {
116131
if (useMassAction) {
117-
if (checkedNodes.includes(node.id)) {
118-
tree.jstree(true).select_node(node.id);
132+
if ($.inArray(childNode.id, isAnchorArr) === -1) {
133+
getAnchorNodeIds(tree, childNode);
119134
}
120-
getCheckedNodeIds(tree, node);
121-
actionBasedOnIsAnchorOnly();
122135
}
123136
});
124137
});
@@ -130,6 +143,9 @@ require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
130143
if (parentNode && parentNode.children.length > 0) {
131144
parentNode.children.forEach(function(childId) {
132145
let childNode = data.instance.get_node(childId, false);
146+
if ($.inArray(childNode.id, isAnchorArr) === -1) {
147+
getAnchorNodeIds(tree, childNode);
148+
}
133149
// Check if the child node has no children (is not yet loaded)
134150
if (childNode.children && childNode.children.length === 0
135151
&& childNode.original && !childNode.original.lastNode) {
@@ -152,6 +168,10 @@ require(['jquery', 'jquery/jstree/jquery.jstree'], function($) {
152168
}
153169
})
154170
}
171+
else if ((parentNode.children.length === 0
172+
&& parentNode.original && parentNode.original.lastNode)) {
173+
getAnchorNodeIds(tree, parentNode);
174+
}
155175
}
156176
157177
var jstreeConfig = {
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 2024 Adobe
5+
* All Rights Reserved.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminVerifySpecificEntityWidgetTreeActionGroup" extends="AdminCreateWidgetActionGroup">
11+
<annotations>
12+
<description>Fill widget main fields and widget layout for anchor categories DisplayOn option. Verify the tree categories selected</description>
13+
</annotations>
14+
<selectOption selector="{{AdminNewWidgetSection.specificEntitySelectContainer}}" userInput="{{widget.container}}" stepKey="setContainer"/>
15+
<seeElement selector="{{AdminNewWidgetSection.specificEntitySelectRadio}}" stepKey="seeSpecificEntityRadio" after="waitForPageLoad"/>
16+
<click selector="{{AdminNewWidgetSection.specificEntitySelectRadio}}" stepKey="clickSpecificEntityRadio" after="seeSpecificEntityRadio"/>
17+
<seeElement selector="{{AdminNewWidgetSection.specificEntityOptionsChooser}}" stepKey="seeChooserTrigger" after="clickSpecificEntityRadio"/>
18+
<click selector="{{AdminNewWidgetSection.specificEntityOptionsChooser}}" stepKey="clickChooserTrigger" after="seeChooserTrigger"/>
19+
<remove keyForRemoval="scrollToTopOfPage"/>
20+
<remove keyForRemoval="clickWidgetOptions"/>
21+
<remove keyForRemoval="waitForWidgetOptions"/>
22+
</actionGroup>
23+
</actionGroups>

app/code/Magento/Widget/Test/Mftf/Section/AdminNewWidgetSection.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
<element name="specificEntitySelectRadio" type="input" selector="#specific_anchor_categories_0"/>
5151
<element name="specificEntityOptionsChooser" type="button" selector="#anchor_categories_ids_0 .widget-option-chooser"/>
5252
<element name="widgetInstanceType" type="select" selector=".admin__field-control select#instance_code" />
53+
<element name="expandJsTree" type="button" selector="//*[@class='chooser']/div/ul/li/i[@role='presentation']"/>
54+
<element name="jsTreeAnchorCheckbox" type="select" selector="//*[@class='chooser']/div/ul[@role='presentation']/li/ul[@role='group']/li/a/i[@class='jstree-icon jstree-checkbox']"/>
5355
<!-- Catalog Product List Widget Options -->
5456
<element name="title" type="input" selector="[name='parameters[title]']"/>
5557
<element name="displayPageControl" type="select" selector="[name='parameters[show_pager]']"/>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<test name="AdminWidgetLayoutSpecificCategoriesTest">
10+
<annotations>
11+
<features value="Widget"/>
12+
<stories value="Content Widget With Anchor and Non Anchor Categories are shown properly"/>
13+
<title value="Anchor and Non Anchor Categories trees with layouts display properly"/>
14+
<description value="Admin should be able to select Anchor and Non Anchor Categories trees successfully"/>
15+
<severity value="CRITICAL"/>
16+
<testCaseId value="ACP2E-3131"/>
17+
<useCaseId value="AC-12581"/>
18+
<group value="Widget"/>
19+
</annotations>
20+
<before>
21+
<!-- Category AN1 is an anchor category -->
22+
<createData entity="_defaultCategory" stepKey="createAnchorCategoryAN1"/>
23+
<!-- Category NA1 is a non-anchor subcategory of category AN1-->
24+
<createData entity="SubCategoryNonAnchor" stepKey="createNonAnchorCategoryNA1">
25+
<requiredEntity createDataKey="createAnchorCategoryAN1"/>
26+
</createData>
27+
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
28+
</before>
29+
<after>
30+
<deleteData createDataKey="createNonAnchorCategoryNA1" stepKey="deleteCategoryNA1"/>
31+
<deleteData createDataKey="createAnchorCategoryAN1" stepKey="deleteCategoryAN1"/>
32+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
33+
</after>
34+
<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToContentWidgetsPageFirst">
35+
<argument name="menuUiId" value="{{AdminMenuContent.dataUiId}}"/>
36+
<argument name="submenuUiId" value="{{AdminMenuContentElementsWidgets.dataUiId}}"/>
37+
</actionGroup>
38+
<actionGroup ref="AdminAssertPageTitleActionGroup" stepKey="seePageTitleFirst">
39+
<argument name="title" value="{{AdminMenuContentElementsWidgets.pageTitle}}"/>
40+
</actionGroup>
41+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear1"/>
42+
<actionGroup ref="AdminVerifySpecificEntityWidgetTreeActionGroup" stepKey="fillForm">
43+
<argument name="widget" value="CatalogCategoryLinkSpecifiedCategory"/>
44+
</actionGroup>
45+
<waitForPageLoad stepKey="waitForDisplayAnchorCategories"/>
46+
<click selector="{{AdminNewWidgetSection.expandJsTree}}" stepKey="clickExpandedJsTree"/>
47+
<waitForPageLoad time="160" stepKey="waitRuleJsTreeAnchorToLoad"/>
48+
<seeElement selector="{{AdminNewWidgetSection.jsTreeAnchorCheckbox}}" stepKey="seeAnchorCheckboxEnabled"/>
49+
</test>
50+
</tests>

0 commit comments

Comments
 (0)