7
7
8
8
namespace Magento \CatalogGraphQl \Model \Resolver ;
9
9
10
- use Magento \Catalog \Model \Category ;
11
10
use Magento \CatalogGraphQl \Model \Resolver \Category \CheckCategoryIsActive ;
12
11
use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \ExtractDataFromCategoryTree ;
13
- use Magento \Framework \Exception \LocalizedException ;
14
12
use Magento \Framework \GraphQl \Config \Element \Field ;
15
13
use Magento \Framework \GraphQl \Exception \GraphQlNoSuchEntityException ;
16
14
use Magento \Framework \GraphQl \Query \ResolverInterface ;
@@ -40,45 +38,20 @@ class CategoryTree implements ResolverInterface
40
38
* @var CheckCategoryIsActive
41
39
*/
42
40
private $ checkCategoryIsActive ;
43
- /**
44
- * @var \Magento\CatalogGraphQl\Model\Category\GetRootCategoryId
45
- */
46
- private $ getRootCategoryId ;
47
41
48
42
/**
49
43
* @param Products\DataProvider\CategoryTree $categoryTree
50
44
* @param ExtractDataFromCategoryTree $extractDataFromCategoryTree
51
45
* @param CheckCategoryIsActive $checkCategoryIsActive
52
- * @param \Magento\CatalogGraphQl\Model\Category\GetRootCategoryId $getRootCategoryId
53
46
*/
54
47
public function __construct (
55
48
Products \DataProvider \CategoryTree $ categoryTree ,
56
49
ExtractDataFromCategoryTree $ extractDataFromCategoryTree ,
57
- CheckCategoryIsActive $ checkCategoryIsActive ,
58
- \Magento \CatalogGraphQl \Model \Category \GetRootCategoryId $ getRootCategoryId
50
+ CheckCategoryIsActive $ checkCategoryIsActive
59
51
) {
60
52
$ this ->categoryTree = $ categoryTree ;
61
53
$ this ->extractDataFromCategoryTree = $ extractDataFromCategoryTree ;
62
54
$ this ->checkCategoryIsActive = $ checkCategoryIsActive ;
63
- $ this ->getRootCategoryId = $ getRootCategoryId ;
64
- }
65
-
66
- /**
67
- * Get category id
68
- *
69
- * @param array $args
70
- * @return int
71
- * @throws GraphQlNoSuchEntityException
72
- */
73
- private function getCategoryId (array $ args ) : int
74
- {
75
- $ rootCategoryId = 0 ;
76
- try {
77
- $ rootCategoryId = isset ($ args ['id ' ]) ? (int )$ args ['id ' ] : $ this ->getRootCategoryId ->execute ();
78
- } catch (LocalizedException $ exception ) {
79
- throw new GraphQlNoSuchEntityException (__ ('Store doesn \'t exist ' ));
80
- }
81
- return $ rootCategoryId ;
82
55
}
83
56
84
57
/**
@@ -90,10 +63,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
90
63
return $ value [$ field ->getName ()];
91
64
}
92
65
93
- $ rootCategoryId = $ this -> getCategoryId ($ args);
94
- if ( $ rootCategoryId !== $ this -> getRootCategoryId -> execute () && $ rootCategoryId > 0 ) {
95
- $ this ->checkCategoryIsActive ->execute ($ rootCategoryId );
96
- }
66
+ $ rootCategoryId = isset ($ args[ ' id ' ]) ? ( int ) $ args [ ' id ' ] :
67
+ $ context -> getExtensionAttributes ()-> getStore ()-> getRootCategoryId ();
68
+ $ this ->checkCategoryIsActive ->execute ($ rootCategoryId );
69
+
97
70
$ categoriesTree = $ this ->categoryTree ->getTree ($ info , $ rootCategoryId );
98
71
99
72
if (empty ($ categoriesTree ) || ($ categoriesTree ->count () == 0 )) {
0 commit comments