Skip to content
Open
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2025 Adobe
* All Rights Reserved.
*/

namespace Magento\Eav\Model\Entity\Collection;
Expand Down Expand Up @@ -1233,8 +1233,27 @@ public function _loadAttributes($printQuery = false, $logQuery = false)
throw $e;
}

$attributeCode = $data = [];
$entityIdField = $entity->getEntityIdField();

foreach ($values as $value) {
$this->_setItemAttributeValue($value);
$entityId = $value[$entityIdField];
$attributeId = $value['attribute_id'];
if (!isset($attributeCode[$attributeId])) {
$attributeCode[$attributeId] = array_search($attributeId, $this->_selectAttributes);
if (!$attributeCode[$attributeId]) {
$attribute = $this->_eavConfig->getAttribute(
$this->getEntity()->getType(),
$attributeId
);
$attributeCode[$attributeId] = $attribute->getAttributeCode();
}
}
$data[$entityId][$attributeCode[$attributeId]] = $value['value'];
}

if ($data) {
$this->_setItemAttributeValues($data);
}
}
}
Expand Down Expand Up @@ -1305,6 +1324,9 @@ protected function _addLoadAttributesSelectValues($select, $table, $type)
*
* Parameter $valueInfo is _getLoadAttributesSelect fetch result row
*
* @deprecated Batch process of attribute values is introduced to reduce time complexity.
* @see _setItemAttributeValues($entityAttributeMap) uses array union (+) to acheive O(n) complexity.
*
* @param array $valueInfo
* @return $this
* @throws LocalizedException
Expand Down Expand Up @@ -1334,6 +1356,33 @@ protected function _setItemAttributeValue($valueInfo)
return $this;
}

/**
* Initialize entity object property value
*
* Parameter $entityAttributeMap is [entity_id => [attribute_code => value, ...]]
*
* @param array $entityAttributeMap
* @return $this
* @throws LocalizedException
*/
protected function _setItemAttributeValues(array $entityAttributeMap)
{
foreach ($entityAttributeMap as $entityId => $attributeValues) {
if (!isset($this->_itemsById[$entityId])) {
throw new LocalizedException(
__('A header row is missing for an attribute. Verify the header row and try again.')
);
}
// _itemsById[$entityId] is always an array (typically with one element)
// foreach handles edge cases where multiple objects share the same entity ID
foreach ($this->_itemsById[$entityId] as $object) {
$object->setData($object->getData()+$attributeValues);
}

}
return $this;
}

/**
* Get alias for attribute value table
*
Expand Down