Skip to content

Commit 1a865fc

Browse files
author
Oleksii Korshenko
committed
MAGETWO-65610: [GitHub][PR] Throw exception when attribute doesn't exitst #7758
- Merge Pull Request #7758 from AydinHassan/magento2:exception-when-attribute-does-not-exist - Merged commits: 1. ed132d0 2. 328b94e
2 parents 2c89e48 + 328b94e commit 1a865fc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

app/code/Magento/Eav/Setup/EavSetup.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ public function updateAttribute($entityTypeId, $id, $field, $value = null, $sort
942942
* @param mixed $value
943943
* @param int $sortOrder
944944
* @return $this
945+
* @throws LocalizedException
945946
*/
946947
private function _updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null)
947948
{
@@ -972,11 +973,15 @@ private function _updateAttribute($entityTypeId, $id, $field, $value = null, $so
972973
return $this;
973974
}
974975
}
976+
$attributeId = $this->getAttributeId($entityTypeId, $id);
977+
if (false === $attributeId) {
978+
throw new LocalizedException(__('Attribute with ID: "%1" does not exist', $id));
979+
}
975980

976981
$this->setup->updateTableRow(
977982
'eav_attribute',
978983
'attribute_id',
979-
$this->getAttributeId($entityTypeId, $id),
984+
$attributeId,
980985
$field,
981986
$value,
982987
'entity_type_id',
@@ -994,6 +999,7 @@ private function _updateAttribute($entityTypeId, $id, $field, $value = null, $so
994999
* @param string|array $field
9951000
* @param mixed $value
9961001
* @return $this
1002+
* @throws LocalizedException
9971003
*/
9981004
private function _updateAttributeAdditionalData($entityTypeId, $id, $field, $value = null)
9991005
{
@@ -1022,6 +1028,11 @@ private function _updateAttributeAdditionalData($entityTypeId, $id, $field, $val
10221028
return $this;
10231029
}
10241030
}
1031+
1032+
$attributeId = $this->getAttributeId($entityTypeId, $id);
1033+
if (false === $attributeId) {
1034+
throw new LocalizedException(__('Attribute with ID: "%1" does not exist', $id));
1035+
}
10251036
$this->setup->updateTableRow(
10261037
$this->setup->getTable($additionalTable),
10271038
'attribute_id',

0 commit comments

Comments
 (0)