9
9
10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
11
use Magento \Catalog \Model \Product ;
12
- use Magento \Catalog \Model \ProductFactory ;
13
12
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Product \Collection as ChildCollection ;
14
13
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Product \CollectionFactory ;
15
14
use Magento \Framework \EntityManager \MetadataPool ;
16
15
use Magento \Framework \Api \SearchCriteriaBuilder ;
17
- use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \Product as DataProvider ;
18
- use Magento \CatalogInventory \Helper \Stock ;
19
- use Magento \CatalogInventory \Api \StockConfigurationInterface ;
16
+ use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \Product \CollectionProcessorInterface ;
20
17
21
18
/**
22
19
* Collection for fetching configurable child product data.
@@ -28,31 +25,11 @@ class Collection
28
25
*/
29
26
private $ childCollectionFactory ;
30
27
31
- /**
32
- * @var ProductFactory
33
- */
34
- private $ productFactory ;
35
-
36
28
/**
37
29
* @var SearchCriteriaBuilder
38
30
*/
39
31
private $ searchCriteriaBuilder ;
40
32
41
- /**
42
- * @var DataProvider
43
- */
44
- private $ productDataProvider ;
45
-
46
- /**
47
- * @var Stock
48
- */
49
- private $ stockHelper ;
50
-
51
- /**
52
- * @var StockConfigurationInterface
53
- */
54
- private $ stockConfig ;
55
-
56
33
/**
57
34
* @var MetadataPool
58
35
*/
@@ -73,31 +50,27 @@ class Collection
73
50
*/
74
51
private $ attributeCodes = [];
75
52
53
+ /**
54
+ * @var CollectionProcessorInterface
55
+ */
56
+ private $ collectionProcessor ;
57
+
76
58
/**
77
59
* @param CollectionFactory $childCollectionFactory
78
- * @param ProductFactory $productFactory
79
60
* @param SearchCriteriaBuilder $searchCriteriaBuilder
80
- * @param DataProvider $productDataProvider
81
61
* @param MetadataPool $metadataPool
82
- * @param Stock $stockHelper
83
- * @param StockConfigurationInterface $stockConfig
62
+ * @param CollectionProcessorInterface $collectionProcessor
84
63
*/
85
64
public function __construct (
86
65
CollectionFactory $ childCollectionFactory ,
87
- ProductFactory $ productFactory ,
88
66
SearchCriteriaBuilder $ searchCriteriaBuilder ,
89
- DataProvider $ productDataProvider ,
90
67
MetadataPool $ metadataPool ,
91
- Stock $ stockHelper ,
92
- StockConfigurationInterface $ stockConfig
68
+ CollectionProcessorInterface $ collectionProcessor
93
69
) {
94
70
$ this ->childCollectionFactory = $ childCollectionFactory ;
95
- $ this ->productFactory = $ productFactory ;
96
71
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
97
- $ this ->productDataProvider = $ productDataProvider ;
98
72
$ this ->metadataPool = $ metadataPool ;
99
- $ this ->stockHelper = $ stockHelper ;
100
- $ this ->stockConfig = $ stockConfig ;
73
+ $ this ->collectionProcessor = $ collectionProcessor ;
101
74
}
102
75
103
76
/**
@@ -161,18 +134,16 @@ private function fetch() : array
161
134
return $ this ->childrenMap ;
162
135
}
163
136
164
- $ showOutOfStock = $ this ->stockConfig ->isShowOutOfStock ();
165
-
166
137
foreach ($ this ->parentProducts as $ product ) {
167
138
$ attributeData = $ this ->getAttributesCodes ($ product );
168
139
/** @var ChildCollection $childCollection */
169
140
$ childCollection = $ this ->childCollectionFactory ->create ();
170
141
$ childCollection ->setProductFilter ($ product );
171
- $ childCollection -> addAttributeToSelect ( $ attributeData );
172
-
173
- if (! $ showOutOfStock ) {
174
- $ this -> stockHelper -> addInStockFilterToCollection ( $ childCollection );
175
- }
142
+ $ this -> collectionProcessor -> process (
143
+ $ childCollection ,
144
+ $ this -> searchCriteriaBuilder -> create (),
145
+ $ attributeData
146
+ );
176
147
177
148
/** @var Product $childProduct */
178
149
foreach ($ childCollection ->getItems () as $ childProduct ) {
0 commit comments