Skip to content

Commit 696e62a

Browse files
Merge branch 2.3-develop into ENGCOM-3964-magento-magento2-20582
2 parents bb8222e + 8e2ca94 commit 696e62a

File tree

8 files changed

+23
-132
lines changed

8 files changed

+23
-132
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,11 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterato
101101

102102
$collection->addFieldToFilter('level', ['gt' => $level]);
103103
$collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]);
104-
$collection->addIsActiveFilter();
105104
$collection->setOrder('level');
106-
$collection->setOrder(
107-
'position',
108-
$collection::SORT_ORDER_DESC
109-
);
110105
$collection->getSelect()->orWhere(
111-
$collection->getSelect()
112-
->getConnection()
113-
->quoteIdentifier(
114-
'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField()
115-
) . ' = ?',
106+
$this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() . ' = ?',
116107
$rootCategoryId
117108
);
118-
119109
return $collection->getIterator();
120110
}
121111

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ class ExtractDataFromCategoryTree
2020
*/
2121
private $categoryHydrator;
2222

23-
/**
24-
* @var CategoryInterface;
25-
*/
26-
private $iteratingCategory;
27-
28-
/**
29-
* @var int
30-
*/
31-
private $startCategoryFetchLevel = 1;
32-
3323
/**
3424
* @param Hydrator $categoryHydrator
3525
*/
@@ -52,63 +42,14 @@ public function execute(\Iterator $iterator): array
5242
/** @var CategoryInterface $category */
5343
$category = $iterator->current();
5444
$iterator->next();
55-
56-
$pathElements = explode("/", $category->getPath());
57-
if (empty($tree)) {
58-
$this->startCategoryFetchLevel = count($pathElements) - 1;
45+
$nextCategory = $iterator->current();
46+
$tree[$category->getId()] = $this->categoryHydrator->hydrateCategory($category);
47+
$tree[$category->getId()]['model'] = $category;
48+
if ($nextCategory && (int) $nextCategory->getLevel() !== (int) $category->getLevel()) {
49+
$tree[$category->getId()]['children'] = $this->execute($iterator);
5950
}
60-
61-
$this->iteratingCategory = $category;
62-
$currentLevelTree = $this->explodePathToArray($pathElements, $this->startCategoryFetchLevel);
63-
if (empty($tree)) {
64-
$tree = $currentLevelTree;
65-
}
66-
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
6751
}
6852

6953
return $tree;
7054
}
71-
72-
/**
73-
* Merge together complex categories trees
74-
*
75-
* @param array $tree1
76-
* @param array $tree2
77-
* @return array
78-
*/
79-
private function mergeCategoriesTrees(array &$tree1, array &$tree2): array
80-
{
81-
$mergedTree = $tree1;
82-
foreach ($tree2 as $currentKey => &$value) {
83-
if (is_array($value) && isset($mergedTree[$currentKey]) && is_array($mergedTree[$currentKey])) {
84-
$mergedTree[$currentKey] = $this->mergeCategoriesTrees($mergedTree[$currentKey], $value);
85-
} else {
86-
$mergedTree[$currentKey] = $value;
87-
}
88-
}
89-
return $mergedTree;
90-
}
91-
92-
/**
93-
* Recursive method to generate tree for one category path
94-
*
95-
* @param array $pathElements
96-
* @param int $index
97-
* @return array
98-
*/
99-
private function explodePathToArray(array $pathElements, int $index): array
100-
{
101-
$tree = [];
102-
$tree[$pathElements[$index]]['id'] = $pathElements[$index];
103-
if ($index === count($pathElements) - 1) {
104-
$tree[$pathElements[$index]] = $this->categoryHydrator->hydrateCategory($this->iteratingCategory);
105-
$tree[$pathElements[$index]]['model'] = $this->iteratingCategory;
106-
}
107-
$currentIndex = $index;
108-
$index++;
109-
if (isset($pathElements[$index])) {
110-
$tree[$pathElements[$currentIndex]]['children'] = $this->explodePathToArray($pathElements, $index);
111-
}
112-
return $tree;
113-
}
11455
}

app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomerAddress.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ private function updateCustomerAddress(int $customerId, int $addressId, array $a
109109
{
110110
$address = $this->getCustomerAddressForUser->execute($addressId, $customerId);
111111
$this->dataObjectHelper->populateWithArray($address, $addressData, AddressInterface::class);
112-
if (isset($addressData['region']['region_id'])) {
113-
$address->setRegionId($address->getRegion()->getRegionId());
114-
}
115-
116112
return $this->addressRepository->save($address);
117113
}
118114
}

app/code/Magento/GraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type Query {
55
}
66

77
type Mutation {
8+
placeholderMutation: String @doc(description: "Mutation type cannot be declared without fields. The placeholder will be removed when at least one mutation field is declared.")
89
}
910

1011
input FilterTypeInput @doc(description: "FilterTypeInput specifies which action will be performed in a query ") {

app/code/Magento/StoreGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type Query {
66

77
type Website @doc(description: "The type contains information about a website") {
88
id : Int @doc(description: "The ID number assigned to the website")
9-
name : String @doc(description: "The website name. Websites use this name to identify it easier.")
9+
name : String @doc(description: "The website name. Websites use this name to identify it easyer.")
1010
code : String @doc(description: "A code assigned to the website to identify it")
1111
sort_order : Int @doc(description: "The attribute to use for sorting websites")
12-
default_group_id : String @doc(description: "The default group ID that the website has")
12+
default_group_id : String @doc(description: "The default group id that the website has")
1313
is_default : Boolean @doc(description: "Specifies if this is the default website")
1414
}
1515

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public function testCategoriesTree()
8383
$responseDataObject = new DataObject($response);
8484
//Some sort of smoke testing
8585
self::assertEquals(
86-
'Its a description of Test Category 1.2',
87-
$responseDataObject->getData('category/children/0/children/1/description')
86+
'Ololo',
87+
$responseDataObject->getData('category/children/7/children/1/description')
8888
);
8989
self::assertEquals(
9090
'default-category',
@@ -99,54 +99,16 @@ public function testCategoriesTree()
9999
$responseDataObject->getData('category/children/0/default_sort_by')
100100
);
101101
self::assertCount(
102-
7,
102+
8,
103103
$responseDataObject->getData('category/children')
104104
);
105105
self::assertCount(
106106
2,
107-
$responseDataObject->getData('category/children/0/children')
107+
$responseDataObject->getData('category/children/7/children')
108108
);
109109
self::assertEquals(
110-
13,
111-
$responseDataObject->getData('category/children/0/children/1/id')
112-
);
113-
}
114-
115-
/**
116-
* @magentoApiDataFixture Magento/Customer/_files/customer.php
117-
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
118-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
119-
*/
120-
public function testGetCategoryById()
121-
{
122-
$rootCategoryId = 13;
123-
$query = <<<QUERY
124-
{
125-
category(id: {$rootCategoryId}) {
126-
id
127-
name
128-
}
129-
}
130-
QUERY;
131-
132-
// get customer ID token
133-
/** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */
134-
$customerTokenService = $this->objectManager->create(
135-
\Magento\Integration\Api\CustomerTokenServiceInterface::class
136-
);
137-
$customerToken = $customerTokenService->createCustomerAccessToken('[email protected]', 'password');
138-
139-
$headerMap = ['Authorization' => 'Bearer ' . $customerToken];
140-
$response = $this->graphQlQuery($query, [], '', $headerMap);
141-
$responseDataObject = new DataObject($response);
142-
//Some sort of smoke testing
143-
self::assertEquals(
144-
'Category 1.2',
145-
$responseDataObject->getData('category/name')
146-
);
147-
self::assertEquals(
148-
13,
149-
$responseDataObject->getData('category/id')
110+
5,
111+
$responseDataObject->getData('category/children/7/children/1/children/0/id')
150112
);
151113
}
152114

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/UpdateCustomerAddressTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ private function assertCustomerAddressesFields(AddressInterface $address, $actua
218218
];
219219
$this->assertResponseFields($actualResponse, $assertionMap);
220220
$this->assertTrue(is_array([$actualResponse['region']]), "region field must be of an array type.");
221-
$assertionRegionMap = [
222-
['response_field' => 'region', 'expected_value' => $address->getRegion()->getRegion()],
223-
['response_field' => 'region_code', 'expected_value' => $address->getRegion()->getRegionCode()],
224-
['response_field' => 'region_id', 'expected_value' => $address->getRegion()->getRegionId()]
225-
];
226-
$this->assertResponseFields($actualResponse['region'], $assertionRegionMap);
221+
// https://github.com/magento/graphql-ce/issues/270
222+
// $assertionRegionMap = [
223+
// ['response_field' => 'region', 'expected_value' => $address->getRegion()->getRegion()],
224+
// ['response_field' => 'region_code', 'expected_value' => $address->getRegion()->getRegionCode()],
225+
// ['response_field' => 'region_id', 'expected_value' => $address->getRegion()->getRegionId()]
226+
// ];
227+
// $this->assertResponseFields($actualResponse['region'], $assertionRegionMap);
227228
}
228229

229230
/**

dev/tests/integration/testsuite/Magento/Catalog/_files/categories.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
->setParentId(3)
179179
->setPath('1/2/3/13')
180180
->setLevel(3)
181-
->setDescription('Its a description of Test Category 1.2')
181+
->setDescription('Ololo')
182182
->setAvailableSortBy('name')
183183
->setDefaultSortBy('name')
184184
->setIsActive(true)

0 commit comments

Comments
 (0)