@@ -148,34 +148,37 @@ private function fetch(ContextInterface $context) : array
148148 return $ this ->childrenMap ;
149149 }
150150
151+ /** @var ChildCollection $childCollection */
152+ $ childCollection = $ this ->childCollectionFactory ->create ();
153+ $ childCollection ->addWebsiteFilter ($ context ->getExtensionAttributes ()->getStore ()->getWebsiteId ());
154+
155+ $ attributeCodes = [];
151156 foreach ($ this ->parentProducts as $ product ) {
152- $ attributeData = $ this ->getAttributesCodes ($ product );
153- /** @var ChildCollection $childCollection */
154- $ childCollection = $ this ->childCollectionFactory ->create ();
155157 $ childCollection ->setProductFilter ($ product );
156- $ childCollection ->addWebsiteFilter ($ context ->getExtensionAttributes ()->getStore ()->getWebsiteId ());
157- $ this ->collectionProcessor ->process (
158- $ childCollection ,
159- $ this ->searchCriteriaBuilder ->create (),
160- $ attributeData ,
161- $ context
162- );
163- $ childCollection ->load ();
164- $ this ->collectionPostProcessor ->process ($ childCollection , $ attributeData );
165-
166- /** @var Product $childProduct */
167- foreach ($ childCollection as $ childProduct ) {
168- if ((int )$ childProduct ->getStatus () !== Status::STATUS_ENABLED ) {
169- continue ;
170- }
171- $ formattedChild = ['model ' => $ childProduct , 'sku ' => $ childProduct ->getSku ()];
172- $ parentId = (int )$ childProduct ->getParentId ();
173- if (!isset ($ this ->childrenMap [$ parentId ])) {
174- $ this ->childrenMap [$ parentId ] = [];
175- }
176-
177- $ this ->childrenMap [$ parentId ][] = $ formattedChild ;
158+ $ attributeCodes [] = $ this ->getAttributesCodes ($ product );
159+ }
160+ $ attributeData = array_unique (array_merge ([], ...$ attributeCodes ));
161+
162+ $ this ->collectionProcessor ->process (
163+ $ childCollection ,
164+ $ this ->searchCriteriaBuilder ->create (),
165+ $ attributeData ,
166+ $ context
167+ );
168+ $ this ->collectionPostProcessor ->process ($ childCollection , $ attributeData );
169+
170+ /** @var Product $childProduct */
171+ foreach ($ childCollection as $ childProduct ) {
172+ if ((int )$ childProduct ->getStatus () !== Status::STATUS_ENABLED ) {
173+ continue ;
174+ }
175+ $ formattedChild = ['model ' => $ childProduct , 'sku ' => $ childProduct ->getSku ()];
176+ $ parentId = (int )$ childProduct ->getParentId ();
177+ if (!isset ($ this ->childrenMap [$ parentId ])) {
178+ $ this ->childrenMap [$ parentId ] = [];
178179 }
180+
181+ $ this ->childrenMap [$ parentId ][] = $ formattedChild ;
179182 }
180183
181184 return $ this ->childrenMap ;
0 commit comments