diff --git a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php index d8762eb604f00..6a1857cb931a6 100644 --- a/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php +++ b/app/code/Magento/Eav/Model/Entity/Collection/AbstractCollection.php @@ -1,7 +1,7 @@ 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->_setItemAttributeValue($data); } } } @@ -1303,7 +1322,7 @@ protected function _addLoadAttributesSelectValues($select, $table, $type) /** * Initialize entity object property value * - * Parameter $valueInfo is _getLoadAttributesSelect fetch result row + * Parameter $valueInfo is [product_id => [attribute_code => value]] * * @param array $valueInfo * @return $this @@ -1311,24 +1330,14 @@ protected function _addLoadAttributesSelectValues($select, $table, $type) */ protected function _setItemAttributeValue($valueInfo) { - $entityIdField = $this->getEntity()->getEntityIdField(); - $entityId = $valueInfo[$entityIdField]; - if (!isset($this->_itemsById[$entityId])) { - throw new LocalizedException( - __('A header row is missing for an attribute. Verify the header row and try again.') - ); - } - $attributeCode = array_search($valueInfo['attribute_id'], $this->_selectAttributes); - if (!$attributeCode) { - $attribute = $this->_eavConfig->getAttribute( - $this->getEntity()->getType(), - $valueInfo['attribute_id'] - ); - $attributeCode = $attribute->getAttributeCode(); - } - - foreach ($this->_itemsById[$entityId] as $object) { - $object->setData($attributeCode, $valueInfo['value']); + foreach ($valueInfo as $entityId => $value) { + if (!isset($this->_itemsById[$entityId])) { + throw new LocalizedException( + __('A header row is missing for an attribute. Verify the header row and try again.') + ); + } + $object =$this->_itemsById[$entityId][0]; + $object->setData($object->getData()+$value); } return $this;