8
8
namespace Magento \CatalogGraphQl \Model \Resolver \Category ;
9
9
10
10
use Magento \Catalog \Model \Category ;
11
- use Magento \Catalog \Model \CategoryRepository ;
12
11
use Magento \Catalog \Model \Product \Visibility ;
13
12
use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \Product \CompositeCollectionProcessor ;
14
13
use Magento \Framework \Api \SearchCriteriaInterface ;
15
- use Magento \Framework \App \ObjectManager ;
16
- use Magento \Framework \GraphQl \Config \Element \Field ;
17
14
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
18
- use Magento \Framework \GraphQl \Query \ResolverInterface ;
19
15
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
16
+ use Magento \Framework \GraphQl \Config \Element \Field ;
17
+ use Magento \Framework \GraphQl \Query \ResolverInterface ;
18
+
20
19
21
20
/**
22
21
* Retrieves products count for a category
@@ -38,27 +37,19 @@ class ProductsCount implements ResolverInterface
38
37
*/
39
38
private $ searchCriteria ;
40
39
41
- /**
42
- * @var CategoryRepository
43
- */
44
- private $ categoryRepository ;
45
-
46
40
/**
47
41
* @param Visibility $catalogProductVisibility
48
42
* @param SearchCriteriaInterface $searchCriteria
49
43
* @param CompositeCollectionProcessor $collectionProcessor
50
- * @param CategoryRepository|null $categoryRepository
51
44
*/
52
45
public function __construct (
53
46
Visibility $ catalogProductVisibility ,
54
47
SearchCriteriaInterface $ searchCriteria ,
55
- CompositeCollectionProcessor $ collectionProcessor ,
56
- ?CategoryRepository $ categoryRepository = null
48
+ CompositeCollectionProcessor $ collectionProcessor
57
49
) {
58
50
$ this ->catalogProductVisibility = $ catalogProductVisibility ;
59
51
$ this ->searchCriteria = $ searchCriteria ;
60
52
$ this ->collectionProcessor = $ collectionProcessor ;
61
- $ this ->categoryRepository = $ categoryRepository ?? ObjectManager::getInstance ()->get (CategoryRepository::class);
62
53
}
63
54
64
55
/**
@@ -71,11 +62,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
71
62
}
72
63
/** @var Category $category */
73
64
$ category = $ value ['model ' ];
74
- $ isAnchored = $ category ->getIsAnchor ();
75
- if (!empty ($ value ['id ' ]) && !$ isAnchored ) {
76
- $ isAnchored = $ this ->categoryRepository ->get ($ value ['id ' ])->getIsAnchor ();
77
- }
78
- $ category ->setIsAnchor ($ isAnchored );
79
65
$ productsCollection = $ category ->getProductCollection ();
80
66
$ productsCollection ->setVisibility ($ this ->catalogProductVisibility ->getVisibleInSiteIds ());
81
67
$ productsCollection = $ this ->collectionProcessor ->process (
@@ -84,7 +70,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
84
70
[],
85
71
$ context
86
72
);
73
+ $ size = $ productsCollection ->getSize ();
87
74
88
- return $ productsCollection -> getSize () ;
75
+ return $ size ;
89
76
}
90
77
}
0 commit comments