@@ -352,45 +352,44 @@ private function attachAttributes(array $attributeIds): void
352
352
$ attributes = $ attributeIds ? $ this ->_prodAttrColFac ->create ()
353
353
->addFieldToFilter (['main_table.attribute_id ' ], [['in ' => $ attributeIds ]])
354
354
->getItems () : [];
355
+ $ attributes = array_filter ($ attributes , fn ($ attribute ) => $ attribute ->getIsVisible ());
355
356
if ($ this ->_forcedAttributesCodes ) {
356
357
$ attributes += $ this ->_prodAttrColFac ->create ()
357
358
->addFieldToFilter (['main_table.attribute_code ' ], [['in ' => $ this ->_forcedAttributesCodes ]])
358
359
->getItems ();
359
360
}
360
361
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 = [];
362
366
foreach ($ attributes as $ attribute ) {
363
367
$ attributeCode = $ attribute ->getAttributeCode ();
364
368
$ 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 ;
391
385
} else {
392
- $ invAttributes [] = $ attributeId ;
386
+ $ cachedAttribute ['options ' ] = $ this ->_entityModel ->getAttributeOptions (
387
+ $ attribute ,
388
+ $ this ->_indexValueAttributes
389
+ );
393
390
}
391
+ $ commonAttributes [$ attributeId ] = $ cachedAttribute ;
392
+ $ attributeCodeToId [$ attributeCode ] = $ attributeId ;
394
393
}
395
394
396
395
foreach (array_chunk ($ attributesToLoadFromTable , 1000 ) as $ ids ) {
@@ -407,7 +406,6 @@ private function attachAttributes(array $attributeIds): void
407
406
408
407
self ::$ commonAttributesCache += $ commonAttributes ;
409
408
self ::$ attributeCodeToId += $ attributeCodeToId ;
410
- self ::$ invAttributesCache = array_merge (self ::$ invAttributesCache , $ invAttributes );
411
409
}
412
410
413
411
/**
@@ -636,9 +634,7 @@ public function saveData()
636
634
protected function getMetadataPool ()
637
635
{
638
636
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);
642
638
}
643
639
return $ this ->metadataPool ;
644
640
}
0 commit comments