@@ -1351,6 +1351,7 @@ protected function _collectSaveData($newObject)
1351
1351
];
1352
1352
}
1353
1353
} elseif (!$ this ->_isAttributeValueEmpty ($ attribute , $ v )) {
1354
+ //one of the attributes (159) ends up here, though it already exists in the table
1354
1355
$ insert [$ attrId ] = is_array ($ v ) ? array_shift ($ v ) : $ v ;//@TODO: MAGETWO-44182
1355
1356
}
1356
1357
}
@@ -1590,7 +1591,30 @@ protected function _processAttributeValues()
1590
1591
{
1591
1592
$ connection = $ this ->getConnection ();
1592
1593
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
+ }
1594
1618
}
1595
1619
1596
1620
foreach ($ this ->_attributeValuesToDelete as $ table => $ valueIds ) {
0 commit comments