@@ -28,6 +28,13 @@ abstract class AbstractType
2828 */
2929 public static $ commonAttributesCache = [];
3030
31+ /**
32+ * Maintain a list of invisible attributes
33+ *
34+ * @var array
35+ */
36+ public static $ invAttributesCache = [];
37+
3138 /**
3239 * Attribute Code to Id cache
3340 *
@@ -278,7 +285,14 @@ protected function _initAttributes()
278285 }
279286 }
280287 foreach ($ absentKeys as $ attributeSetName => $ attributeIds ) {
281- $ this ->attachAttributesById ($ attributeSetName , $ attributeIds );
288+ $ unknownAttributeIds = array_diff (
289+ $ attributeIds ,
290+ array_keys (self ::$ commonAttributesCache ),
291+ self ::$ invAttributesCache
292+ );
293+ if ($ unknownAttributeIds || $ this ->_forcedAttributesCodes ) {
294+ $ this ->attachAttributesById ($ attributeSetName , $ attributeIds );
295+ }
282296 }
283297 foreach ($ entityAttributes as $ attributeRow ) {
284298 if (isset (self ::$ commonAttributesCache [$ attributeRow ['attribute_id ' ]])) {
@@ -303,37 +317,45 @@ protected function _initAttributes()
303317 protected function attachAttributesById ($ attributeSetName , $ attributeIds )
304318 {
305319 foreach ($ this ->_prodAttrColFac ->create ()->addFieldToFilter (
306- 'main_table.attribute_id ' ,
307- ['in ' => $ attributeIds ]
320+ ['main_table.attribute_id ' , 'main_table.attribute_code ' ],
321+ [
322+ ['in ' => $ attributeIds ],
323+ ['in ' => $ this ->_forcedAttributesCodes ]
324+ ]
308325 ) as $ attribute ) {
309326 $ attributeCode = $ attribute ->getAttributeCode ();
310327 $ attributeId = $ attribute ->getId ();
311328
312329 if ($ attribute ->getIsVisible () || in_array ($ attributeCode , $ this ->_forcedAttributesCodes )) {
313- self ::$ commonAttributesCache [$ attributeId ] = [
314- 'id ' => $ attributeId ,
315- 'code ' => $ attributeCode ,
316- 'is_global ' => $ attribute ->getIsGlobal (),
317- 'is_required ' => $ attribute ->getIsRequired (),
318- 'is_unique ' => $ attribute ->getIsUnique (),
319- 'frontend_label ' => $ attribute ->getFrontendLabel (),
320- 'is_static ' => $ attribute ->isStatic (),
321- 'apply_to ' => $ attribute ->getApplyTo (),
322- 'type ' => \Magento \ImportExport \Model \Import::getAttributeType ($ attribute ),
323- 'default_value ' => strlen (
324- $ attribute ->getDefaultValue ()
325- ) ? $ attribute ->getDefaultValue () : null ,
326- 'options ' => $ this ->_entityModel ->getAttributeOptions (
327- $ attribute ,
328- $ this ->_indexValueAttributes
329- ),
330- ];
330+ if (!isset (self ::$ commonAttributesCache [$ attributeId ])) {
331+ self ::$ commonAttributesCache [$ attributeId ] = [
332+ 'id ' => $ attributeId ,
333+ 'code ' => $ attributeCode ,
334+ 'is_global ' => $ attribute ->getIsGlobal (),
335+ 'is_required ' => $ attribute ->getIsRequired (),
336+ 'is_unique ' => $ attribute ->getIsUnique (),
337+ 'frontend_label ' => $ attribute ->getFrontendLabel (),
338+ 'is_static ' => $ attribute ->isStatic (),
339+ 'apply_to ' => $ attribute ->getApplyTo (),
340+ 'type ' => \Magento \ImportExport \Model \Import::getAttributeType ($ attribute ),
341+ 'default_value ' => strlen (
342+ $ attribute ->getDefaultValue ()
343+ ) ? $ attribute ->getDefaultValue () : null ,
344+ 'options ' => $ this ->_entityModel ->getAttributeOptions (
345+ $ attribute ,
346+ $ this ->_indexValueAttributes
347+ ),
348+ ];
349+ }
350+
331351 self ::$ attributeCodeToId [$ attributeCode ] = $ attributeId ;
332352 $ this ->_addAttributeParams (
333353 $ attributeSetName ,
334354 self ::$ commonAttributesCache [$ attributeId ],
335355 $ attribute
336356 );
357+ } else {
358+ self ::$ invAttributesCache [] = $ attributeId ;
337359 }
338360 }
339361 }
0 commit comments