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