@@ -194,6 +194,11 @@ class Eav extends AbstractModifier
194
194
*/
195
195
private $ attributesCache = [];
196
196
197
+ /**
198
+ * @var AttributeCollectionFactory
199
+ */
200
+ private $ attributeCollectionFactory ;
201
+
197
202
/**
198
203
* @param LocatorInterface $locator
199
204
* @param CatalogEavValidationRules $catalogEavValidationRules
@@ -214,6 +219,7 @@ class Eav extends AbstractModifier
214
219
* @param DataPersistorInterface $dataPersistor
215
220
* @param array $attributesToDisable
216
221
* @param array $attributesToEliminate
222
+ * @param AttributeCollectionFactory $attributeCollectionFactory
217
223
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
218
224
*/
219
225
public function __construct (
@@ -257,8 +263,8 @@ public function __construct(
257
263
$ this ->dataPersistor = $ dataPersistor ;
258
264
$ this ->attributesToDisable = $ attributesToDisable ;
259
265
$ this ->attributesToEliminate = $ attributesToEliminate ;
260
- $ this ->attributeCollectionFactory = $ attributeCollectionFactory ?: \ Magento \ Framework \ App \ObjectManager:: getInstance ()
261
- ->get (AttributeCollectionFactory::class);
266
+ $ this ->attributeCollectionFactory = $ attributeCollectionFactory
267
+ ?: \ Magento \ Framework \ App \ObjectManager:: getInstance () ->get (AttributeCollectionFactory::class);
262
268
}
263
269
264
270
/**
@@ -502,37 +508,8 @@ private function getAttributes()
502
508
}
503
509
504
510
/**
505
- * Loading product attributes from group
511
+ * Loads attributes for specified groups at once
506
512
*
507
- * @param AttributeGroupInterface $group
508
- * @return ProductAttributeInterface[]
509
- */
510
- private function loadAttributes (AttributeGroupInterface $ group )
511
- {
512
- $ attributes = [];
513
- $ sortOrder = $ this ->sortOrderBuilder
514
- ->setField ('sort_order ' )
515
- ->setAscendingDirection ()
516
- ->create ();
517
- $ searchCriteria = $ this ->searchCriteriaBuilder
518
- ->addFilter (AttributeGroupInterface::GROUP_ID , $ group ->getAttributeGroupId ())
519
- ->addFilter (ProductAttributeInterface::IS_VISIBLE , 1 )
520
- ->addSortOrder ($ sortOrder )
521
- ->create ();
522
- $ groupAttributes = $ this ->attributeRepository ->getList ($ searchCriteria )->getItems ();
523
- $ productType = $ this ->getProductType ();
524
- foreach ($ groupAttributes as $ attribute ) {
525
- $ applyTo = $ attribute ->getApplyTo ();
526
- $ isRelated = !$ applyTo || in_array ($ productType , $ applyTo );
527
- if ($ isRelated ) {
528
- $ attributes [] = $ attribute ;
529
- }
530
- }
531
-
532
- return $ attributes ;
533
- }
534
-
535
- /**
536
513
* @param AttributeGroupInterface[] ...$groups
537
514
* @return @return ProductAttributeInterface[]
538
515
*/
@@ -541,7 +518,6 @@ private function loadAttributesForGroups(array $groups)
541
518
$ attributes = [];
542
519
$ groupIds = [];
543
520
544
- // foreach just works faster than array_walk() or array_column()
545
521
foreach ($ groups as $ group ) {
546
522
$ groupIds [$ group ->getAttributeGroupId ()] = $ this ->calculateGroupCode ($ group );
547
523
$ attributes [$ this ->calculateGroupCode ($ group )] = [];
@@ -550,12 +526,10 @@ private function loadAttributesForGroups(array $groups)
550
526
$ collection = $ this ->attributeCollectionFactory ->create ();
551
527
$ collection ->setAttributeGroupFilter (array_keys ($ groupIds ));
552
528
553
- $ attrs = $ collection ->getItems ();
554
-
555
- $ map = [];
529
+ $ mapAttributeToGroup = [];
556
530
557
- foreach ($ attrs as $ a ) {
558
- $ map [ $ a ->getAttributeId ()] = $ a ->getAttributeGroupId ();
531
+ foreach ($ collection -> getItems () as $ attribute ) {
532
+ $ mapAttributeToGroup [ $ attribute ->getAttributeId ()] = $ attribute ->getAttributeGroupId ();
559
533
}
560
534
561
535
$ sortOrder = $ this ->sortOrderBuilder
@@ -577,7 +551,7 @@ private function loadAttributesForGroups(array $groups)
577
551
$ applyTo = $ attribute ->getApplyTo ();
578
552
$ isRelated = !$ applyTo || in_array ($ productType , $ applyTo );
579
553
if ($ isRelated ) {
580
- $ attributeGroupId = $ map [$ attribute ->getAttributeId ()];
554
+ $ attributeGroupId = $ mapAttributeToGroup [$ attribute ->getAttributeId ()];
581
555
$ attributeGroupCode = $ groupIds [$ attributeGroupId ];
582
556
$ attributes [$ attributeGroupCode ][] = $ attribute ;
583
557
}
0 commit comments