8
8
namespace Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider ;
9
9
10
10
use Magento \Catalog \Model \Product \Visibility ;
11
+ use Magento \Catalog \Model \ResourceModel \CategoryProduct ;
12
+ use Magento \Framework \Api \SearchCriteriaBuilder ;
11
13
use Magento \Framework \Api \SearchCriteriaInterface ;
12
14
use Magento \Catalog \Model \ResourceModel \Product \CollectionFactory ;
15
+ use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
16
+ use Magento \Framework \Api \SearchCriteria \CollectionProcessorInterface ;
13
17
use Magento \Catalog \Api \Data \ProductSearchResultsInterfaceFactory ;
14
18
use Magento \Framework \Api \SearchResultsInterface ;
15
- use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \Product \CollectionProcessorInterface ;
16
19
17
20
/**
18
21
* Product field data provider, used for GraphQL resolver processing.
@@ -25,36 +28,73 @@ class Product
25
28
private $ collectionFactory ;
26
29
27
30
/**
28
- * @var ProductSearchResultsInterfaceFactory
31
+ * @var JoinProcessorInterface
29
32
*/
30
- private $ searchResultsFactory ;
33
+ private $ joinProcessor ;
31
34
32
35
/**
33
36
* @var CollectionProcessorInterface
34
37
*/
35
38
private $ collectionProcessor ;
36
39
40
+ /**
41
+ * @var ProductSearchResultsInterfaceFactory
42
+ */
43
+ private $ searchResultsFactory ;
44
+
45
+ /**
46
+ * @var CategoryProduct
47
+ */
48
+ private $ categoryProduct ;
49
+
50
+ /**
51
+ * @var SearchCriteriaBuilder
52
+ */
53
+ private $ searchCriteriaBuilder ;
54
+
55
+ /**
56
+ * @var \Magento\Catalog\Model\Layer\Resolver
57
+ */
58
+ private $ layerResolver ;
59
+
60
+ /**
61
+ * @var \Magento\Catalog\Model\ProductRepository
62
+ */
63
+ private $ productRepository ;
64
+
37
65
/**
38
66
* @var Visibility
39
67
*/
40
68
private $ visibility ;
41
69
42
70
/**
43
71
* @param CollectionFactory $collectionFactory
44
- * @param ProductSearchResultsInterfaceFactory $searchResultsFactory
45
- * @param Visibility $visibility
72
+ * @param JoinProcessorInterface $joinProcessor
46
73
* @param CollectionProcessorInterface $collectionProcessor
74
+ * @param ProductSearchResultsInterfaceFactory $searchResultsFactory
75
+ * @param CategoryProduct $categoryProduct
76
+ * @param SearchCriteriaBuilder $searchCriteriaBuilder
47
77
*/
48
78
public function __construct (
49
79
CollectionFactory $ collectionFactory ,
80
+ JoinProcessorInterface $ joinProcessor ,
81
+ CollectionProcessorInterface $ collectionProcessor ,
50
82
ProductSearchResultsInterfaceFactory $ searchResultsFactory ,
51
- Visibility $ visibility ,
52
- CollectionProcessorInterface $ collectionProcessor
83
+ CategoryProduct $ categoryProduct ,
84
+ SearchCriteriaBuilder $ searchCriteriaBuilder ,
85
+ \Magento \Catalog \Model \Layer \Resolver $ layerResolver ,
86
+ \Magento \Catalog \Model \ProductRepository $ productRepository ,
87
+ Visibility $ visibility
53
88
) {
54
89
$ this ->collectionFactory = $ collectionFactory ;
90
+ $ this ->joinProcessor = $ joinProcessor ;
91
+ $ this ->collectionProcessor = $ collectionProcessor ;
55
92
$ this ->searchResultsFactory = $ searchResultsFactory ;
93
+ $ this ->categoryProduct = $ categoryProduct ;
94
+ $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
56
95
$ this ->visibility = $ visibility ;
57
- $ this ->collectionProcessor = $ collectionProcessor ;
96
+ $ this ->layerResolver = $ layerResolver ;
97
+ $ this ->productRepository = $ productRepository ;
58
98
}
59
99
60
100
/**
@@ -74,17 +114,29 @@ public function getList(
74
114
): SearchResultsInterface {
75
115
/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
76
116
$ collection = $ this ->collectionFactory ->create ();
117
+ $ this ->joinProcessor ->process ($ collection );
77
118
78
- $ this ->collectionProcessor ->process ($ collection , $ searchCriteria , $ attributes );
119
+ foreach ($ attributes as $ attributeCode ) {
120
+ $ collection ->addAttributeToSelect ($ attributeCode );
121
+ }
122
+ $ collection ->addAttributeToSelect ('special_price ' );
123
+ $ collection ->addAttributeToSelect ('special_price_from ' );
124
+ $ collection ->addAttributeToSelect ('special_price_to ' );
125
+ $ collection ->addAttributeToSelect ('tax_class_id ' );
126
+ $ collection ->joinAttribute ('status ' , 'catalog_product/status ' , 'entity_id ' , null , 'inner ' );
127
+ $ collection ->joinAttribute ('visibility ' , 'catalog_product/visibility ' , 'entity_id ' , null , 'inner ' );
79
128
80
129
if (!$ isChildSearch ) {
81
130
$ visibilityIds
82
131
= $ isSearch ? $ this ->visibility ->getVisibleInSearchIds () : $ this ->visibility ->getVisibleInCatalogIds ();
83
132
$ collection ->setVisibility ($ visibilityIds );
84
133
}
134
+
135
+ $ this ->collectionProcessor ->process ($ searchCriteria , $ collection );
136
+ $ collection ->addWebsiteNamesToResult ();
85
137
$ collection ->load ();
86
138
87
- // Methods that perform extra fetches post-load
139
+ // Methods that perform extra fetches
88
140
$ collection ->addCategoryIds ();
89
141
$ collection ->addMediaGalleryData ();
90
142
$ collection ->addOptionsToResult ();
0 commit comments