10
10
use Magento \Catalog \Api \Data \ProductInterface ;
11
11
use Magento \Catalog \Model \Product ;
12
12
use Magento \Catalog \Model \ProductFactory ;
13
- use Magento \Catalog \Model \ProductRepository ;
14
- use Magento \ConfigurableProduct \Helper \Data ;
15
13
use Magento \ConfigurableProduct \Model \Product \Type \Configurable \Attribute ;
16
14
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Attribute \Collection
17
15
as AttributeCollection ;
18
16
use Magento \ConfigurableProduct \Model \ResourceModel \Product \Type \Configurable \Attribute \CollectionFactory ;
19
- use Magento \Framework \Api \SearchCriteriaBuilder ;
20
- use Magento \Framework \App \ObjectManager ;
21
17
use Magento \Framework \EntityManager \MetadataPool ;
22
18
23
19
/**
@@ -35,36 +31,11 @@ class Collection
35
31
*/
36
32
private $ productFactory ;
37
33
38
- /**
39
- * @var ProductRepository
40
- */
41
- private $ productRepository ;
42
-
43
34
/**
44
35
* @var MetadataPool
45
36
*/
46
37
private $ metadataPool ;
47
38
48
- /**
49
- * @var Data
50
- */
51
- private $ configurableProductHelper ;
52
-
53
- /**
54
- * @var Metadata
55
- */
56
- private $ optionsMetadata ;
57
-
58
- /**
59
- * @var SelectionUidFormatter
60
- */
61
- private $ selectionUidFormatter ;
62
-
63
- /**
64
- * @var SearchCriteriaBuilder
65
- */
66
- private $ searchCriteriaBuilder ;
67
-
68
39
/**
69
40
* @var int[]
70
41
*/
@@ -78,32 +49,16 @@ class Collection
78
49
/**
79
50
* @param CollectionFactory $attributeCollectionFactory
80
51
* @param ProductFactory $productFactory
81
- * @param ProductRepository $productRepository
82
52
* @param MetadataPool $metadataPool
83
- * @param Data $configurableProductHelper
84
- * @param Metadata $optionsMetadata
85
- * @param SelectionUidFormatter $selectionUidFormatter
86
- * @param SearchCriteriaBuilder $searchCriteriaBuilder
87
53
*/
88
54
public function __construct (
89
55
CollectionFactory $ attributeCollectionFactory ,
90
56
ProductFactory $ productFactory ,
91
- ProductRepository $ productRepository ,
92
- MetadataPool $ metadataPool ,
93
- Data $ configurableProductHelper ,
94
- Metadata $ optionsMetadata ,
95
- SelectionUidFormatter $ selectionUidFormatter ,
96
- SearchCriteriaBuilder $ searchCriteriaBuilder
57
+ MetadataPool $ metadataPool
97
58
) {
98
59
$ this ->attributeCollectionFactory = $ attributeCollectionFactory ;
99
60
$ this ->productFactory = $ productFactory ;
100
- $ this ->productRepository = $ productRepository ;
101
61
$ this ->metadataPool = $ metadataPool ;
102
- $ this ->configurableProductHelper = $ configurableProductHelper ;
103
- $ this ->optionsMetadata = $ optionsMetadata ;
104
- $ this ->selectionUidFormatter = $ selectionUidFormatter ;
105
- $ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ??
106
- ObjectManager::getInstance ()->get (SearchCriteriaBuilder::class);
107
62
}
108
63
109
64
/**
@@ -156,8 +111,6 @@ private function fetch() : array
156
111
$ attributeCollection ->setProductFilter ($ product );
157
112
}
158
113
159
- $ products = $ this ->getProducts ($ this ->productIds );
160
-
161
114
/** @var Attribute $attribute */
162
115
foreach ($ attributeCollection ->getItems () as $ attribute ) {
163
116
$ productId = (int )$ attribute ->getProductId ();
@@ -175,42 +128,8 @@ private function fetch() : array
175
128
$ this ->attributeMap [$ productId ][$ attribute ->getId ()]['values ' ] = $ attributeData ['options ' ];
176
129
$ this ->attributeMap [$ productId ][$ attribute ->getId ()]['label ' ]
177
130
= $ attribute ->getProductAttribute ()->getStoreLabel ();
178
-
179
- if (isset ($ products [$ productId ])) {
180
- $ options = $ this ->configurableProductHelper ->getOptions (
181
- $ products [$ productId ],
182
- $ this ->optionsMetadata ->getAllowProducts ($ products [$ productId ])
183
- );
184
- foreach ($ attributeData ['options ' ] as $ index => $ value ) {
185
- $ this ->attributeMap [$ productId ][$ attribute ->getId ()]['values ' ][$ index ]['uid ' ]
186
- = $ this ->selectionUidFormatter ->encode ((int )$ attribute ->getId (), (int )$ value ['value_index ' ]);
187
- $ this ->attributeMap [$ productId ][$ attribute ->getId ()]['values ' ][$ index ]
188
- ['is_available_for_selection ' ] =
189
- isset ($ options [$ attribute ->getAttributeId ()][$ value ['value_index ' ]])
190
- && $ options [$ attribute ->getAttributeId ()][$ value ['value_index ' ]];
191
- }
192
- }
193
131
}
194
132
195
133
return $ this ->attributeMap ;
196
134
}
197
-
198
- /**
199
- * Load products by link field ids
200
- *
201
- * @param int[] $productIds
202
- * @return ProductInterface[]
203
- */
204
- private function getProducts ($ productIds )
205
- {
206
- $ linkField = $ this ->metadataPool ->getMetadata (ProductInterface::class)->getLinkField ();
207
- $ this ->searchCriteriaBuilder ->addFilter ($ linkField , $ productIds , 'in ' );
208
- $ searchCriteria = $ this ->searchCriteriaBuilder ->create ();
209
- $ products = $ this ->productRepository ->getList ($ searchCriteria )->getItems ();
210
- $ productsLinkFieldMap = [];
211
- foreach ($ products as $ product ) {
212
- $ productsLinkFieldMap [$ product ->getData ($ linkField )] = $ product ;
213
- }
214
- return $ productsLinkFieldMap ;
215
- }
216
135
}
0 commit comments