@@ -352,45 +352,44 @@ private function attachAttributes(array $attributeIds): void
352352 $ attributes = $ attributeIds ? $ this ->_prodAttrColFac ->create ()
353353 ->addFieldToFilter (['main_table.attribute_id ' ], [['in ' => $ attributeIds ]])
354354 ->getItems () : [];
355+ $ attributes = array_filter ($ attributes , fn ($ attribute ) => $ attribute ->getIsVisible ());
355356 if ($ this ->_forcedAttributesCodes ) {
356357 $ attributes += $ this ->_prodAttrColFac ->create ()
357358 ->addFieldToFilter (['main_table.attribute_code ' ], [['in ' => $ this ->_forcedAttributesCodes ]])
358359 ->getItems ();
359360 }
360361
361- $ commonAttributes = $ attributeCodeToId = $ attributesToLoadFromTable = $ invAttributes = [];
362+ $ invAttributes = array_diff ($ attributeIds , array_keys ($ attributes ));
363+ self ::$ invAttributesCache = array_merge (self ::$ invAttributesCache , $ invAttributes );
364+
365+ $ commonAttributes = $ attributeCodeToId = $ attributesToLoadFromTable = [];
362366 foreach ($ attributes as $ attribute ) {
363367 $ attributeCode = $ attribute ->getAttributeCode ();
364368 $ attributeId = $ attribute ->getId ();
365- if ($ attribute ->getIsVisible () || in_array ($ attributeCode , $ this ->_forcedAttributesCodes )) {
366- $ defaultValue = $ attribute ->getDefaultValue ();
367- $ cachedAttribute = [
368- 'id ' => $ attributeId ,
369- 'code ' => $ attributeCode ,
370- 'is_global ' => $ attribute ->getIsGlobal (),
371- 'is_required ' => $ attribute ->getIsRequired (),
372- 'is_unique ' => $ attribute ->getIsUnique (),
373- 'frontend_label ' => $ attribute ->getFrontendLabel (),
374- 'is_static ' => $ attribute ->isStatic (),
375- 'apply_to ' => $ attribute ->getApplyTo (),
376- 'type ' => Import::getAttributeType ($ attribute ),
377- 'default_value ' => is_string ($ defaultValue ) && strlen ($ defaultValue ) ? $ defaultValue : null ,
378- 'options ' => [],
379- ];
380- if (Table::class === $ attribute ->getSourceModel ()) {
381- $ attributesToLoadFromTable [] = $ attributeId ;
382- } else {
383- $ cachedAttribute ['options ' ] = $ this ->_entityModel ->getAttributeOptions (
384- $ attribute ,
385- $ this ->_indexValueAttributes
386- );
387- }
388-
389- $ commonAttributes [$ attributeId ] = $ cachedAttribute ;
390- $ attributeCodeToId [$ attributeCode ] = $ attributeId ;
369+ $ defaultValue = $ attribute ->getDefaultValue ();
370+ $ cachedAttribute = [
371+ 'id ' => $ attributeId ,
372+ 'code ' => $ attributeCode ,
373+ 'is_global ' => $ attribute ->getIsGlobal (),
374+ 'is_required ' => $ attribute ->getIsRequired (),
375+ 'is_unique ' => $ attribute ->getIsUnique (),
376+ 'frontend_label ' => $ attribute ->getFrontendLabel (),
377+ 'is_static ' => $ attribute ->isStatic (),
378+ 'apply_to ' => $ attribute ->getApplyTo (),
379+ 'type ' => Import::getAttributeType ($ attribute ),
380+ 'default_value ' => is_string ($ defaultValue ) && strlen ($ defaultValue ) ? $ defaultValue : null ,
381+ 'options ' => [],
382+ ];
383+ if (Table::class === $ attribute ->getSourceModel ()) {
384+ $ attributesToLoadFromTable [] = $ attributeId ;
391385 } else {
392- $ invAttributes [] = $ attributeId ;
386+ $ cachedAttribute ['options ' ] = $ this ->_entityModel ->getAttributeOptions (
387+ $ attribute ,
388+ $ this ->_indexValueAttributes
389+ );
393390 }
391+ $ commonAttributes [$ attributeId ] = $ cachedAttribute ;
392+ $ attributeCodeToId [$ attributeCode ] = $ attributeId ;
394393 }
395394
396395 foreach (array_chunk ($ attributesToLoadFromTable , 1000 ) as $ ids ) {
@@ -407,7 +406,6 @@ private function attachAttributes(array $attributeIds): void
407406
408407 self ::$ commonAttributesCache += $ commonAttributes ;
409408 self ::$ attributeCodeToId += $ attributeCodeToId ;
410- self ::$ invAttributesCache = array_merge (self ::$ invAttributesCache , $ invAttributes );
411409 }
412410
413411 /**
@@ -636,9 +634,7 @@ public function saveData()
636634 protected function getMetadataPool ()
637635 {
638636 if (!$ this ->metadataPool ) {
639- // phpcs:ignore Magento2.PHP.AutogeneratedClassNotInConstructor
640- $ this ->metadataPool = \Magento \Framework \App \ObjectManager::getInstance ()
641- ->get (MetadataPool::class);
637+ $ this ->metadataPool = \Magento \Framework \App \ObjectManager::getInstance ()->get (MetadataPool::class);
642638 }
643639 return $ this ->metadataPool ;
644640 }
0 commit comments