99
1010use Magento \Catalog \Model \Category ;
1111use Magento \Catalog \Model \Product \Visibility ;
12- use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \Product \CollectionProcessor \ StockProcessor ;
12+ use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \Product \CompositeCollectionProcessor ;
1313use Magento \Framework \Api \SearchCriteriaInterface ;
1414use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
1515use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
1616use Magento \Framework \GraphQl \Config \Element \Field ;
1717use Magento \Framework \GraphQl \Query \ResolverInterface ;
1818
19+
1920/**
2021 * Retrieves products count for a category
2122 */
@@ -27,9 +28,9 @@ class ProductsCount implements ResolverInterface
2728 private $ catalogProductVisibility ;
2829
2930 /**
30- * @var StockProcessor
31+ * @var CompositeCollectionProcessor
3132 */
32- private $ stockProcessor ;
33+ private $ collectionProcessor ;
3334
3435 /**
3536 * @var SearchCriteriaInterface
@@ -39,16 +40,16 @@ class ProductsCount implements ResolverInterface
3940 /**
4041 * @param Visibility $catalogProductVisibility
4142 * @param SearchCriteriaInterface $searchCriteria
42- * @param StockProcessor $stockProcessor
43+ * @param CompositeCollectionProcessor $collectionProcessor
4344 */
4445 public function __construct (
4546 Visibility $ catalogProductVisibility ,
4647 SearchCriteriaInterface $ searchCriteria ,
47- StockProcessor $ stockProcessor
48+ CompositeCollectionProcessor $ collectionProcessor
4849 ) {
4950 $ this ->catalogProductVisibility = $ catalogProductVisibility ;
5051 $ this ->searchCriteria = $ searchCriteria ;
51- $ this ->stockProcessor = $ stockProcessor ;
52+ $ this ->collectionProcessor = $ collectionProcessor ;
5253 }
5354
5455 /**
@@ -63,8 +64,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6364 $ category = $ value ['model ' ];
6465 $ productsCollection = $ category ->getProductCollection ();
6566 $ productsCollection ->setVisibility ($ this ->catalogProductVisibility ->getVisibleInSiteIds ());
66- $ productsCollection = $ this ->stockProcessor ->process ($ productsCollection , $ this ->searchCriteria , []);
67+ $ productsCollection = $ this ->collectionProcessor ->process (
68+ $ productsCollection ,
69+ $ this ->searchCriteria ,
70+ [],
71+ $ context
72+ );
73+ $ size = $ productsCollection ->getSize ();
6774
68- return $ productsCollection -> getSize () ;
75+ return $ size ;
6976 }
7077}
0 commit comments