@@ -28,6 +28,13 @@ abstract class AbstractType
28
28
*/
29
29
public static $ commonAttributesCache = [];
30
30
31
+ /**
32
+ * Maintain a list of invisible attributes
33
+ *
34
+ * @var array
35
+ */
36
+ public static $ invAttributesCache = [];
37
+
31
38
/**
32
39
* Attribute Code to Id cache
33
40
*
@@ -278,7 +285,14 @@ protected function _initAttributes()
278
285
}
279
286
}
280
287
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
+ }
282
296
}
283
297
foreach ($ entityAttributes as $ attributeRow ) {
284
298
if (isset (self ::$ commonAttributesCache [$ attributeRow ['attribute_id ' ]])) {
@@ -303,37 +317,45 @@ protected function _initAttributes()
303
317
protected function attachAttributesById ($ attributeSetName , $ attributeIds )
304
318
{
305
319
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
+ ]
308
325
) as $ attribute ) {
309
326
$ attributeCode = $ attribute ->getAttributeCode ();
310
327
$ attributeId = $ attribute ->getId ();
311
328
312
329
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
+
331
351
self ::$ attributeCodeToId [$ attributeCode ] = $ attributeId ;
332
352
$ this ->_addAttributeParams (
333
353
$ attributeSetName ,
334
354
self ::$ commonAttributesCache [$ attributeId ],
335
355
$ attribute
336
356
);
357
+ } else {
358
+ self ::$ invAttributesCache [] = $ attributeId ;
337
359
}
338
360
}
339
361
}
0 commit comments