@@ -123,11 +123,12 @@ public function addEavAttributes(array $attributeCodes) : void
123123 *
124124 * @param int $id
125125 * @param ContextInterface $context
126+ * @param array $attributeCodes
126127 * @return array
127128 */
128- public function getChildProductsByParentId (int $ id , ContextInterface $ context ) : array
129+ public function getChildProductsByParentId (int $ id , ContextInterface $ context, array $ attributeCodes ) : array
129130 {
130- $ childrenMap = $ this ->fetch ($ context );
131+ $ childrenMap = $ this ->fetch ($ context, $ attributeCodes );
131132
132133 if (!isset ($ childrenMap [$ id ])) {
133134 return [];
@@ -140,9 +141,10 @@ public function getChildProductsByParentId(int $id, ContextInterface $context) :
140141 * Fetch all children products from parent id's.
141142 *
142143 * @param ContextInterface $context
144+ * @param array $attributeCodes
143145 * @return array
144146 */
145- private function fetch (ContextInterface $ context ) : array
147+ private function fetch (ContextInterface $ context, array $ attributeCodes ) : array
146148 {
147149 if (empty ($ this ->parentProducts ) || !empty ($ this ->childrenMap )) {
148150 return $ this ->childrenMap ;
@@ -152,20 +154,13 @@ private function fetch(ContextInterface $context) : array
152154 $ childCollection = $ this ->childCollectionFactory ->create ();
153155 $ childCollection ->addWebsiteFilter ($ context ->getExtensionAttributes ()->getStore ()->getWebsiteId ());
154156
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-
162157 $ this ->collectionProcessor ->process (
163158 $ childCollection ,
164159 $ this ->searchCriteriaBuilder ->create (),
165- $ attributeData ,
160+ $ attributeCodes ,
166161 $ context
167162 );
168- $ this ->collectionPostProcessor ->process ($ childCollection , $ attributeData );
163+ $ this ->collectionPostProcessor ->process ($ childCollection , $ attributeCodes );
169164
170165 /** @var Product $childProduct */
171166 foreach ($ childCollection as $ childProduct ) {
@@ -184,28 +179,6 @@ private function fetch(ContextInterface $context) : array
184179 return $ this ->childrenMap ;
185180 }
186181
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-
209182 /**
210183 * @inheritDoc
211184 */
0 commit comments