@@ -123,11 +123,12 @@ public function addEavAttributes(array $attributeCodes) : void
123
123
*
124
124
* @param int $id
125
125
* @param ContextInterface $context
126
+ * @param array $attributeCodes
126
127
* @return array
127
128
*/
128
- public function getChildProductsByParentId (int $ id , ContextInterface $ context ) : array
129
+ public function getChildProductsByParentId (int $ id , ContextInterface $ context, array $ attributeCodes ) : array
129
130
{
130
- $ childrenMap = $ this ->fetch ($ context );
131
+ $ childrenMap = $ this ->fetch ($ context, $ attributeCodes );
131
132
132
133
if (!isset ($ childrenMap [$ id ])) {
133
134
return [];
@@ -140,9 +141,10 @@ public function getChildProductsByParentId(int $id, ContextInterface $context) :
140
141
* Fetch all children products from parent id's.
141
142
*
142
143
* @param ContextInterface $context
144
+ * @param array $attributeCodes
143
145
* @return array
144
146
*/
145
- private function fetch (ContextInterface $ context ) : array
147
+ private function fetch (ContextInterface $ context, array $ attributeCodes ) : array
146
148
{
147
149
if (empty ($ this ->parentProducts ) || !empty ($ this ->childrenMap )) {
148
150
return $ this ->childrenMap ;
@@ -152,20 +154,13 @@ private function fetch(ContextInterface $context) : array
152
154
$ childCollection = $ this ->childCollectionFactory ->create ();
153
155
$ childCollection ->addWebsiteFilter ($ context ->getExtensionAttributes ()->getStore ()->getWebsiteId ());
154
156
155
- $ attributeCodes = [];
156
- foreach ($ this ->parentProducts as $ product ) {
157
- $ childCollection ->setProductFilter ($ product );
158
- $ attributeCodes [] = $ this ->getAttributesCodes ($ product );
159
- }
160
- $ attributeData = array_unique (array_merge ([], ...$ attributeCodes ));
161
-
162
157
$ this ->collectionProcessor ->process (
163
158
$ childCollection ,
164
159
$ this ->searchCriteriaBuilder ->create (),
165
- $ attributeData ,
160
+ $ attributeCodes ,
166
161
$ context
167
162
);
168
- $ this ->collectionPostProcessor ->process ($ childCollection , $ attributeData );
163
+ $ this ->collectionPostProcessor ->process ($ childCollection , $ attributeCodes );
169
164
170
165
/** @var Product $childProduct */
171
166
foreach ($ childCollection as $ childProduct ) {
@@ -184,28 +179,6 @@ private function fetch(ContextInterface $context) : array
184
179
return $ this ->childrenMap ;
185
180
}
186
181
187
- /**
188
- * Get attributes codes for given product
189
- *
190
- * @param Product $currentProduct
191
- * @return array
192
- */
193
- private function getAttributesCodes (Product $ currentProduct ): array
194
- {
195
- $ attributeCodes = $ this ->attributeCodes ;
196
- if ($ currentProduct ->getTypeId () == Configurable::TYPE_CODE ) {
197
- $ allowAttributes = $ currentProduct ->getTypeInstance ()->getConfigurableAttributes ($ currentProduct );
198
- foreach ($ allowAttributes as $ attribute ) {
199
- $ productAttribute = $ attribute ->getProductAttribute ();
200
- if (!\in_array ($ productAttribute ->getAttributeCode (), $ attributeCodes )) {
201
- $ attributeCodes [] = $ productAttribute ->getAttributeCode ();
202
- }
203
- }
204
- }
205
-
206
- return $ attributeCodes ;
207
- }
208
-
209
182
/**
210
183
* @inheritDoc
211
184
*/
0 commit comments