File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,9 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterato
85
85
{
86
86
$ categoryQuery = $ resolveInfo ->fieldNodes [0 ];
87
87
$ collection = $ this ->collectionFactory ->create ();
88
+ if ($ this ->isRootCategoryActive ($ collection , $ rootCategoryId ) == false ) {
89
+ throw new \Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException (__ ('Category doesn \'t exist ' ));
90
+ }
88
91
$ this ->joinAttributesRecursively ($ collection , $ categoryQuery );
89
92
$ depth = $ this ->depthCalculator ->calculate ($ categoryQuery );
90
93
$ level = $ this ->levelCalculator ->calculate ($ rootCategoryId );
@@ -144,4 +147,29 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi
144
147
$ this ->joinAttributesRecursively ($ collection , $ node );
145
148
}
146
149
}
150
+
151
+ /**
152
+ * @param Collection $collection
153
+ * @param int $rootCategoryId
154
+ *
155
+ * @return bool
156
+ * @throws \Exception
157
+ */
158
+ private function isRootCategoryActive (Collection $ collection , int $ rootCategoryId ) : bool
159
+ {
160
+ if ($ rootCategoryId == Category::TREE_ROOT_ID ) {
161
+ return true ;
162
+ }
163
+ $ collection ->addAttributeToFilter (Category::KEY_IS_ACTIVE , ['eq ' => 1 ])
164
+ ->getSelect ()
165
+ ->where (
166
+ $ collection ->getSelect ()
167
+ ->getConnection ()
168
+ ->quoteIdentifier (
169
+ 'e. ' . $ this ->metadata ->getMetadata (CategoryInterface::class)->getIdentifierField ()
170
+ ) . ' = ? ' ,
171
+ $ rootCategoryId
172
+ );
173
+ return (bool ) $ collection ->count ();
174
+ }
147
175
}
Original file line number Diff line number Diff line change 9
9
10
10
use Magento \CatalogGraphQl \Model \Category \Hydrator ;
11
11
use Magento \Catalog \Api \Data \CategoryInterface ;
12
- use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
13
- use Magento \Catalog \Model \Category ;
14
12
15
13
/**
16
14
* Extract data from category tree
@@ -53,9 +51,6 @@ public function execute(\Iterator $iterator): array
53
51
while ($ iterator ->valid ()) {
54
52
/** @var CategoryInterface $category */
55
53
$ category = $ iterator ->current ();
56
- if ($ category ->getIsActive () == false && $ category ->getId () != Category::TREE_ROOT_ID ) {
57
- throw new GraphQlNoSuchEntityException (__ ('Category doesn \'t exist ' ));
58
- }
59
54
$ iterator ->next ();
60
55
$ pathElements = explode ("/ " , $ category ->getPath ());
61
56
if (empty ($ tree )) {
You can’t perform that action at this time.
0 commit comments