9
9
10
10
use Exception ;
11
11
use Magento \Catalog \Api \Data \ProductSearchResultsInterfaceFactory ;
12
+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory as CategoryCollectionFactory ;
12
13
use Magento \CatalogGraphQl \DataProvider \Product \SearchCriteriaBuilder ;
13
14
use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \ProductSearch ;
14
15
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
@@ -87,6 +88,11 @@ class Search extends CoreSearch
87
88
*/
88
89
protected $ emulateSearchResult ;
89
90
91
+ /**
92
+ * @var CategoryCollectionFactory
93
+ */
94
+ protected CategoryCollectionFactory $ categoryCollectionFactory ;
95
+
90
96
/**
91
97
* @param SearchInterface $search
92
98
* @param SearchResultFactory $searchResultFactory
@@ -99,6 +105,7 @@ class Search extends CoreSearch
99
105
* @param DataPostProcessor $productPostProcessor
100
106
* @param QueryFactory $queryFactory
101
107
* @param StoreManagerInterface $storeManager
108
+ * @param CategoryCollectionFactory $categoryCollectionFactory
102
109
*/
103
110
public function __construct (
104
111
SearchInterface $ search ,
@@ -111,7 +118,8 @@ public function __construct(
111
118
SearchCriteriaBuilder $ searchCriteriaBuilder ,
112
119
DataPostProcessor $ productPostProcessor ,
113
120
QueryFactory $ queryFactory ,
114
- StoreManagerInterface $ storeManager
121
+ StoreManagerInterface $ storeManager ,
122
+ CategoryCollectionFactory $ categoryCollectionFactory
115
123
) {
116
124
parent ::__construct (
117
125
$ search ,
@@ -133,6 +141,7 @@ public function __construct(
133
141
$ this ->storeManager = $ storeManager ;
134
142
$ this ->productSearchResultsInterfaceFactory = $ productSearchResultsInterfaceFactory ;
135
143
$ this ->emulateSearchResult = $ emulateSearchResult ;
144
+ $ this ->categoryCollectionFactory = $ categoryCollectionFactory ;
136
145
}
137
146
138
147
/**
@@ -153,6 +162,21 @@ public function getResult(
153
162
$ searchCriteria = $ this ->buildSearchCriteria ($ args , $ info );
154
163
$ itemsResults = $ this ->getSearchResults ($ searchCriteria , $ info );
155
164
165
+ // When adding a new product through the admin panel, it does not appear
166
+ // on the category page (without cleaning cache), if the category won`t
167
+ // mentions in request in Magento Tags (and not just product Tags as now).
168
+ //
169
+ // To add the category to tags, need to cause category loading when receiving products for it
170
+ // (only loading is enough because the tags are added to load_after)
171
+ //
172
+ // Related task: https://github.com/scandipwa/scandipwa/issues/4353
173
+ if (!empty ($ args ['filter ' ]['category_id ' ])) {
174
+ $ this ->categoryCollectionFactory ->create ()
175
+ ->addAttributeToSelect ('entity_id ' )
176
+ ->addAttributeToFilter ('entity_id ' , $ args ['filter ' ]['category_id ' ])
177
+ ->load ();
178
+ }
179
+
156
180
if ($ this ->includeItems ($ info )) {
157
181
// load product collection only if items are requested
158
182
$ searchResults = $ this ->productsProvider ->getList (
0 commit comments