Skip to content

Commit 3603cc2

Browse files
committed
ACP2E-1358, replaced insertOnDuplicateKey with corresponding insert / update queries for attributes
1 parent 9c42b97 commit 3603cc2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,7 @@ protected function _collectSaveData($newObject)
13511351
];
13521352
}
13531353
} elseif (!$this->_isAttributeValueEmpty($attribute, $v)) {
1354+
//one of the attributes (159) ends up here, though it already exists in the table
13541355
$insert[$attrId] = is_array($v) ? array_shift($v) : $v;//@TODO: MAGETWO-44182
13551356
}
13561357
}
@@ -1590,7 +1591,30 @@ protected function _processAttributeValues()
15901591
{
15911592
$connection = $this->getConnection();
15921593
foreach ($this->_attributeValuesToSave as $table => $data) {
1593-
$connection->insertOnDuplicate($table, $data, array_keys($data[0]));
1594+
$insert = [];
1595+
foreach ($data as $attributeData) {
1596+
$select = $connection->select()->from($table, 'value_id')->where("entity_id = :entity_id AND attribute_id = :attribute_id");
1597+
$result = $connection->fetchOne($select, [
1598+
'attribute_id' => $attributeData['attribute_id'],
1599+
'entity_id' => $attributeData['entity_id']
1600+
]);
1601+
if ($result) {
1602+
$updateWhere = [];
1603+
$updateWhere[] = sprintf('%s=%d', $connection->quoteIdentifier('entity_id'), $attributeData['entity_id']);
1604+
$updateWhere[] = sprintf('%s=%d', $connection->quoteIdentifier('attribute_id'), $attributeData['attribute_id']);
1605+
$connection->update($table, ['value' => $attributeData['value']], $updateWhere);
1606+
} else {
1607+
$insert[] = [
1608+
'attribute_id' => $attributeData['attribute_id'],
1609+
'entity_id' => $attributeData['entity_id'],
1610+
'value' => $attributeData['value']
1611+
];
1612+
}
1613+
}
1614+
1615+
if (!empty($insert)) {
1616+
$connection->insertArray($table, array_keys($insert[0]), $insert);
1617+
}
15941618
}
15951619

15961620
foreach ($this->_attributeValuesToDelete as $table => $valueIds) {

0 commit comments

Comments
 (0)