|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Copyright 2013 Adobe |
| 3 | + * Copyright 2025 Adobe |
4 | 4 | * All Rights Reserved. |
5 | 5 | */ |
6 | 6 |
|
@@ -1233,8 +1233,27 @@ public function _loadAttributes($printQuery = false, $logQuery = false) |
1233 | 1233 | throw $e; |
1234 | 1234 | } |
1235 | 1235 |
|
| 1236 | + $attributeCode = $data = []; |
| 1237 | + $entityIdField = $entity->getEntityIdField(); |
| 1238 | + |
1236 | 1239 | foreach ($values as $value) { |
1237 | | - $this->_setItemAttributeValue($value); |
| 1240 | + $entityId = $value[$entityIdField]; |
| 1241 | + $attributeId = $value['attribute_id']; |
| 1242 | + if (!isset($attributeCode[$attributeId])) { |
| 1243 | + $attributeCode[$attributeId] = array_search($attributeId, $this->_selectAttributes); |
| 1244 | + if (!$attributeCode[$attributeId]) { |
| 1245 | + $attribute = $this->_eavConfig->getAttribute( |
| 1246 | + $this->getEntity()->getType(), |
| 1247 | + $attributeId |
| 1248 | + ); |
| 1249 | + $attributeCode[$attributeId] = $attribute->getAttributeCode(); |
| 1250 | + } |
| 1251 | + } |
| 1252 | + $data[$entityId][$attributeCode[$attributeId]] = $value['value']; |
| 1253 | + } |
| 1254 | + |
| 1255 | + if ($data) { |
| 1256 | + $this->_setItemAttributeValues($data); |
1238 | 1257 | } |
1239 | 1258 | } |
1240 | 1259 | } |
@@ -1305,6 +1324,9 @@ protected function _addLoadAttributesSelectValues($select, $table, $type) |
1305 | 1324 | * |
1306 | 1325 | * Parameter $valueInfo is _getLoadAttributesSelect fetch result row |
1307 | 1326 | * |
| 1327 | + * @deprecated Batch process of attribute values is introduced to reduce time complexity. |
| 1328 | + * @see _setItemAttributeValues($entityAttributeMap) uses array union (+) to acheive O(n) complexity. |
| 1329 | + * |
1308 | 1330 | * @param array $valueInfo |
1309 | 1331 | * @return $this |
1310 | 1332 | * @throws LocalizedException |
@@ -1334,6 +1356,33 @@ protected function _setItemAttributeValue($valueInfo) |
1334 | 1356 | return $this; |
1335 | 1357 | } |
1336 | 1358 |
|
| 1359 | + /** |
| 1360 | + * Initialize entity object property value |
| 1361 | + * |
| 1362 | + * Parameter $entityAttributeMap is [entity_id => [attribute_code => value, ...]] |
| 1363 | + * |
| 1364 | + * @param array $entityAttributeMap |
| 1365 | + * @return $this |
| 1366 | + * @throws LocalizedException |
| 1367 | + */ |
| 1368 | + protected function _setItemAttributeValues(array $entityAttributeMap) |
| 1369 | + { |
| 1370 | + foreach ($entityAttributeMap as $entityId => $attributeValues) { |
| 1371 | + if (!isset($this->_itemsById[$entityId])) { |
| 1372 | + throw new LocalizedException( |
| 1373 | + __('A header row is missing for an attribute. Verify the header row and try again.') |
| 1374 | + ); |
| 1375 | + } |
| 1376 | + // _itemsById[$entityId] is always an array (typically with one element) |
| 1377 | + // foreach handles edge cases where multiple objects share the same entity ID |
| 1378 | + foreach ($this->_itemsById[$entityId] as $object) { |
| 1379 | + $object->setData($object->getData()+$attributeValues); |
| 1380 | + } |
| 1381 | + |
| 1382 | + } |
| 1383 | + return $this; |
| 1384 | + } |
| 1385 | + |
1337 | 1386 | /** |
1338 | 1387 | * Get alias for attribute value table |
1339 | 1388 | * |
|
0 commit comments