Skip to content

Commit 92a4477

Browse files
ENGCOM-7112: FIX #14080 Added improvements to Category repository (save method) #27304
- Merge Pull Request #27304 from sergiy-v/magento2:14080-category-repository-save-improvements - Merged commits: 1. 4da150c
2 parents ecaa3b7 + 4da150c commit 92a4477

9 files changed

+135
-1
lines changed

app/code/Magento/Catalog/Model/CategoryRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
108108
$parentCategory = $this->get($parentId, $storeId);
109109
$existingData['path'] = $parentCategory->getPath();
110110
$existingData['parent_id'] = $parentId;
111+
$existingData['level'] = null;
111112
}
112113
$category->addData($existingData);
113114
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminAssertParentChildCategoryTreeElementsActionGroup">
12+
<annotations>
13+
<description>Checks category tree, parent category has child category element.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="parentCategoryName" type="string" defaultValue="parent"/>
17+
<argument name="childCategoryName" type="string" defaultValue="child"/>
18+
</arguments>
19+
20+
<seeElement selector="{{AdminCategorySidebarTreeSection.childCategoryUnderParent(parentCategoryName, childCategoryName)}}" stepKey="seeSubcategoryIsUnderParent"/>
21+
</actionGroup>
22+
</actionGroups>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminExpandCategoryTreeActionGroup">
12+
<annotations>
13+
<description>Expands category tree.</description>
14+
</annotations>
15+
16+
<click selector="{{AdminCategorySidebarTreeSection.expandAll}}" stepKey="clickOnExpandTree"/>
17+
<waitForPageLoad stepKey="waitForCategoryToLoad"/>
18+
</actionGroup>
19+
</actionGroups>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminOpenCategoryPageActionGroup">
12+
<annotations>
13+
<description>Navigates to category page.</description>
14+
</annotations>
15+
16+
<amOnPage url="{{AdminCategoryPage.url}}" stepKey="openAdminCategoryIndexPage"/>
17+
<waitForPageLoad stepKey="waitForCategoryPageToLoad"/>
18+
</actionGroup>
19+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertAdminCategoryLevelByParentCategoryLevelActionGroup">
12+
<annotations>
13+
<description>Checks category level by parent category level.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="parentCategoryLevel" type="string" defaultValue="2"/>
17+
<argument name="categoryLevel" type="string" defaultValue="3"/>
18+
</arguments>
19+
20+
<assertEquals expected="{{parentCategoryLevel}} + 1" actual="{{categoryLevel}}" message="wrongCategoryLevel" stepKey="compareCategoryLevel"/>
21+
</actionGroup>
22+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Data/CategoryData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,10 @@
259259
<data key="include_in_menu">true</data>
260260
<var key="parent_id" entityType="category" entityKey="id"/>
261261
</entity>
262+
<entity name="ApiSubCategoryWithLevelZero" type="category">
263+
<data key="name" unique="suffix">cat with level 1</data>
264+
<data key="is_active">true</data>
265+
<data key="level">0</data>
266+
<var key="parent_id" entityType="category" entityKey="id"/>
267+
</entity>
262268
</entities>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<element name="categoryTreeRoot" type="text" selector="div.x-tree-root-node>li.x-tree-node:first-of-type>div.x-tree-node-el:first-of-type" timeout="30"/>
1717
<element name="categoryInTree" type="text" selector="//a/span[contains(text(), '{{name}}')]" parameterized="true" timeout="30"/>
1818
<element name="categoryInTreeUnderRoot" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{name}}')]" parameterized="true"/>
19+
<element name="childCategoryUnderParent" type="text" selector="//li/ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{parentCategoryName}}')]/../../../ul/li[@class='x-tree-node']/div/a/span[contains(text(), '{{childCategoryName}}')]" parameterized="true"/>
1920
<element name="lastCreatedCategory" type="block" selector=".x-tree-root-ct li li:last-child" />
2021
<element name="treeContainer" type="block" selector=".tree-holder" />
2122
<element name="expandRootCategory" type="text" selector="img.x-tree-elbow-end-plus"/>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminCheckNewCategoryLevelAddedViaApiTest">
12+
<annotations>
13+
<stories value="Add parent and child categories via API"/>
14+
<title value="Add parent and child categories via API"/>
15+
<description value="Login as admin, create parent and child categories via API.
16+
Check category level for child category entity based on parent level.
17+
Check category tree: parent element has child element. "/>
18+
<group value="catalog"/>
19+
</annotations>
20+
<before>
21+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginToAdminPanel"/>
22+
<createData entity="ApiCategoryWithChildren" stepKey="createCategoryWithChildrenBlank"/>
23+
<createData entity="ApiSubCategoryWithLevelZero" stepKey="createSubCategoryWithLevelZero">
24+
<requiredEntity createDataKey="createCategoryWithChildrenBlank"/>
25+
</createData>
26+
</before>
27+
<after>
28+
<deleteData createDataKey="createCategoryWithChildrenBlank" stepKey="deleteCategoryWithChildrenBlank"/>
29+
<actionGroup ref="logout" stepKey="logout"/>
30+
</after>
31+
32+
<actionGroup ref="AssertAdminCategoryLevelByParentCategoryLevelActionGroup" stepKey="assertCategoryLevelByParentCategory">
33+
<argument name="parentCategoryLevel" value="$createCategoryWithChildrenBlank.level$"/>
34+
<argument name="categoryLevel" value="$createSubCategoryWithLevelZero.level$"/>
35+
</actionGroup>
36+
37+
<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openCategoryPage"/>
38+
<actionGroup ref="AdminExpandCategoryTreeActionGroup" stepKey="expandCategoryTree"/>
39+
<actionGroup ref="AdminAssertParentChildCategoryTreeElementsActionGroup" stepKey="assertParentChildCategoryTreeElements">
40+
<argument name="parentCategoryName" value="$createCategoryWithChildrenBlank.name$"/>
41+
<argument name="childCategoryName" value="$createSubCategoryWithLevelZero.name$"/>
42+
</actionGroup>
43+
</test>
44+
</tests>

app/code/Magento/Catalog/Test/Unit/Model/CategoryRepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function testCreateNewCategory()
204204
$parentCategoryId = 15;
205205
$newCategoryId = 25;
206206
$categoryData = ['level' => '1', 'path' => '1/2', 'parent_id' => 1, 'name' => 'category'];
207-
$dataForSave = ['store_id' => 1, 'name' => 'category', 'path' => 'path', 'parent_id' => 15];
207+
$dataForSave = ['store_id' => 1, 'name' => 'category', 'path' => 'path', 'parent_id' => 15, 'level' => null];
208208
$this->extensibleDataObjectConverterMock
209209
->expects($this->once())
210210
->method('toNestedArray')

0 commit comments

Comments
 (0)