7
7
8
8
namespace Magento \CatalogGraphQl \Model \Category ;
9
9
10
- use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
- use Magento \Catalog \Api \Data \CategorySearchResultsInterface ;
12
- use Magento \Catalog \Api \Data \CategorySearchResultsInterfaceFactory ;
13
10
use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory ;
14
11
use Magento \CatalogGraphQl \Model \Resolver \Categories \DataProvider \Category \CollectionProcessorInterface ;
15
12
use Magento \CatalogGraphQl \Model \Category \Filter \SearchCriteria ;
@@ -40,16 +37,6 @@ class CategoryFilter
40
37
*/
41
38
private $ extensionAttributesJoinProcessor ;
42
39
43
- /**
44
- * @var CategorySearchResultsInterfaceFactory
45
- */
46
- private $ categorySearchResultsFactory ;
47
-
48
- /**
49
- * @var CategoryRepositoryInterface
50
- */
51
- private $ categoryRepository ;
52
-
53
40
/**
54
41
* @var SearchCriteria
55
42
*/
@@ -59,23 +46,17 @@ class CategoryFilter
59
46
* @param CollectionFactory $categoryCollectionFactory
60
47
* @param CollectionProcessorInterface $collectionProcessor
61
48
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
62
- * @param CategorySearchResultsInterfaceFactory $categorySearchResultsFactory
63
- * @param CategoryRepositoryInterface $categoryRepository
64
49
* @param SearchCriteria $searchCriteria
65
50
*/
66
51
public function __construct (
67
52
CollectionFactory $ categoryCollectionFactory ,
68
53
CollectionProcessorInterface $ collectionProcessor ,
69
54
JoinProcessorInterface $ extensionAttributesJoinProcessor ,
70
- CategorySearchResultsInterfaceFactory $ categorySearchResultsFactory ,
71
- CategoryRepositoryInterface $ categoryRepository ,
72
55
SearchCriteria $ searchCriteria
73
56
) {
74
57
$ this ->categoryCollectionFactory = $ categoryCollectionFactory ;
75
58
$ this ->collectionProcessor = $ collectionProcessor ;
76
59
$ this ->extensionAttributesJoinProcessor = $ extensionAttributesJoinProcessor ;
77
- $ this ->categorySearchResultsFactory = $ categorySearchResultsFactory ;
78
- $ this ->categoryRepository = $ categoryRepository ;
79
60
$ this ->searchCriteria = $ searchCriteria ;
80
61
}
81
62
@@ -96,27 +77,21 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu
96
77
$ this ->extensionAttributesJoinProcessor ->process ($ collection );
97
78
$ this ->collectionProcessor ->process ($ collection , $ searchCriteria , $ attributeNames , $ context );
98
79
99
- /** @var CategorySearchResultsInterface $searchResult */
100
- $ categories = $ this ->categorySearchResultsFactory ->create ();
101
- $ categories ->setSearchCriteria ($ searchCriteria );
102
-
103
80
// only fetch necessary category entity id
104
- $ select = $ collection-> getSelect ();
105
- $ select
81
+ $ collection
82
+ -> getSelect ()
106
83
->reset (Select::COLUMNS )
107
84
->columns (
108
85
'e.entity_id '
109
86
);
110
- $ categoryIds = array_map ('intval ' , $ collection ->getConnection ()->fetchCol ($ select ));
111
87
112
- $ categories ->setItems ($ categoryIds );
113
- $ categories ->setTotalCount (count ($ categoryIds ));
88
+ $ categoryIds = $ collection ->getLoadedIds ();
114
89
115
90
$ totalPages = 0 ;
116
- if ($ categories -> getTotalCount () > 0 && $ searchCriteria ->getPageSize () > 0 ) {
117
- $ totalPages = ceil ($ categories -> getTotalCount () / $ searchCriteria ->getPageSize ());
91
+ if ($ collection -> getSize () > 0 && $ searchCriteria ->getPageSize () > 0 ) {
92
+ $ totalPages = ceil ($ collection -> getSize () / $ searchCriteria ->getPageSize ());
118
93
}
119
- if ($ searchCriteria ->getCurrentPage () > $ totalPages && $ categories -> getTotalCount () > 0 ) {
94
+ if ($ searchCriteria ->getCurrentPage () > $ totalPages && $ collection -> getSize () > 0 ) {
120
95
throw new GraphQlInputException (
121
96
__ (
122
97
'currentPage value %1 specified is greater than the %2 page(s) available. ' ,
@@ -127,7 +102,7 @@ public function getResult(array $criteria, StoreInterface $store, array $attribu
127
102
128
103
return [
129
104
'category_ids ' => $ categoryIds ,
130
- 'total_count ' => $ categories -> getTotalCount (),
105
+ 'total_count ' => $ collection -> getSize (),
131
106
'page_info ' => [
132
107
'total_pages ' => $ totalPages ,
133
108
'page_size ' => $ searchCriteria ->getPageSize (),
0 commit comments