File tree Expand file tree Collapse file tree 2 files changed +48
-4
lines changed
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider
dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog Expand file tree Collapse file tree 2 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
class ExtractDataFromCategoryTree
17
17
{
18
- const START_CATEGORY_FETCH_LEVEL = 1 ;
19
-
20
18
/**
21
19
* @var Hydrator
22
20
*/
@@ -27,6 +25,11 @@ class ExtractDataFromCategoryTree
27
25
*/
28
26
private $ iteratingCategory ;
29
27
28
+ /**
29
+ * @var int
30
+ */
31
+ private $ startCategoryFetchLevel = 1 ;
32
+
30
33
/**
31
34
* @param Hydrator $categoryHydrator
32
35
*/
@@ -51,9 +54,12 @@ public function execute(\Iterator $iterator): array
51
54
$ iterator ->next ();
52
55
53
56
$ pathElements = explode ("/ " , $ category ->getPath ());
54
- $ this ->iteratingCategory = $ category ;
57
+ if (empty ($ tree )){
58
+ $ this ->startCategoryFetchLevel = count ($ pathElements ) - 1 ;
59
+ }
55
60
56
- $ currentLevelTree = $ this ->explodePathToArray ($ pathElements , self ::START_CATEGORY_FETCH_LEVEL );
61
+ $ this ->iteratingCategory = $ category ;
62
+ $ currentLevelTree = $ this ->explodePathToArray ($ pathElements , $ this ->startCategoryFetchLevel );
57
63
if (empty ($ tree )) {
58
64
$ tree = $ currentLevelTree ;
59
65
}
Original file line number Diff line number Diff line change @@ -112,6 +112,44 @@ public function testCategoriesTree()
112
112
);
113
113
}
114
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 ('customer@example.com ' , '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 ' )
150
+ );
151
+ }
152
+
115
153
/**
116
154
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
117
155
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
You can’t perform that action at this time.
0 commit comments