Skip to content

Commit c3aa634

Browse files
MAGETWO-92693: Some improvements on product create|edit page in admin area
1 parent ae0933c commit c3aa634

File tree

1 file changed

+13
-39
lines changed
  • app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier

1 file changed

+13
-39
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ class Eav extends AbstractModifier
194194
*/
195195
private $attributesCache = [];
196196

197+
/**
198+
* @var AttributeCollectionFactory
199+
*/
200+
private $attributeCollectionFactory;
201+
197202
/**
198203
* @param LocatorInterface $locator
199204
* @param CatalogEavValidationRules $catalogEavValidationRules
@@ -214,6 +219,7 @@ class Eav extends AbstractModifier
214219
* @param DataPersistorInterface $dataPersistor
215220
* @param array $attributesToDisable
216221
* @param array $attributesToEliminate
222+
* @param AttributeCollectionFactory $attributeCollectionFactory
217223
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
218224
*/
219225
public function __construct(
@@ -257,8 +263,8 @@ public function __construct(
257263
$this->dataPersistor = $dataPersistor;
258264
$this->attributesToDisable = $attributesToDisable;
259265
$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);
262268
}
263269

264270
/**
@@ -502,37 +508,8 @@ private function getAttributes()
502508
}
503509

504510
/**
505-
* Loading product attributes from group
511+
* Loads attributes for specified groups at once
506512
*
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-
/**
536513
* @param AttributeGroupInterface[] ...$groups
537514
* @return @return ProductAttributeInterface[]
538515
*/
@@ -541,7 +518,6 @@ private function loadAttributesForGroups(array $groups)
541518
$attributes = [];
542519
$groupIds = [];
543520

544-
// foreach just works faster than array_walk() or array_column()
545521
foreach ($groups as $group) {
546522
$groupIds[$group->getAttributeGroupId()] = $this->calculateGroupCode($group);
547523
$attributes[$this->calculateGroupCode($group)] = [];
@@ -550,12 +526,10 @@ private function loadAttributesForGroups(array $groups)
550526
$collection = $this->attributeCollectionFactory->create();
551527
$collection->setAttributeGroupFilter(array_keys($groupIds));
552528

553-
$attrs = $collection->getItems();
554-
555-
$map = [];
529+
$mapAttributeToGroup = [];
556530

557-
foreach ($attrs as $a) {
558-
$map[$a->getAttributeId()] = $a->getAttributeGroupId();
531+
foreach ($collection->getItems() as $attribute) {
532+
$mapAttributeToGroup[$attribute->getAttributeId()] = $attribute->getAttributeGroupId();
559533
}
560534

561535
$sortOrder = $this->sortOrderBuilder
@@ -577,7 +551,7 @@ private function loadAttributesForGroups(array $groups)
577551
$applyTo = $attribute->getApplyTo();
578552
$isRelated = !$applyTo || in_array($productType, $applyTo);
579553
if ($isRelated) {
580-
$attributeGroupId = $map[$attribute->getAttributeId()];
554+
$attributeGroupId = $mapAttributeToGroup[$attribute->getAttributeId()];
581555
$attributeGroupCode = $groupIds[$attributeGroupId];
582556
$attributes[$attributeGroupCode][] = $attribute;
583557
}

0 commit comments

Comments
 (0)