@@ -1592,22 +1592,12 @@ protected function _processAttributeValues()
15921592 foreach ($ this ->_attributeValuesToSave as $ table => $ data ) {
15931593 $ insert = [];
15941594 foreach ($ data as $ attributeData ) {
1595- $ select = $ connection ->select ()->from ($ table , 'value_id ' )->where ("entity_id = :entity_id AND attribute_id = :attribute_id " );
1596- $ result = $ connection ->fetchOne ($ select , [
1597- 'attribute_id ' => $ attributeData ['attribute_id ' ],
1598- 'entity_id ' => $ attributeData ['entity_id ' ]
1599- ]);
1600- if ($ result ) {
1601- $ updateWhere = [];
1602- $ updateWhere [] = sprintf ('%s=%d ' , $ connection ->quoteIdentifier ('entity_id ' ), $ attributeData ['entity_id ' ]);
1603- $ updateWhere [] = sprintf ('%s=%d ' , $ connection ->quoteIdentifier ('attribute_id ' ), $ attributeData ['attribute_id ' ]);
1604- $ connection ->update ($ table , ['value ' => $ attributeData ['value ' ]], $ updateWhere );
1595+ $ whereValues = $ attributeData ;
1596+ unset($ whereValues ['value ' ]);
1597+ if ($ valueId = $ this ->checkExistingAttributeValue ($ table , $ attributeData )) {
1598+ $ connection ->update ($ table , ['value ' => $ attributeData ['value ' ]], $ valueId );
16051599 } else {
1606- $ insert [] = [
1607- 'attribute_id ' => $ attributeData ['attribute_id ' ],
1608- 'entity_id ' => $ attributeData ['entity_id ' ],
1609- 'value ' => $ attributeData ['value ' ]
1610- ];
1600+ $ insert [] = $ attributeData ;
16111601 }
16121602 }
16131603
@@ -1627,6 +1617,27 @@ protected function _processAttributeValues()
16271617 return $ this ;
16281618 }
16291619
1620+ /**
1621+ * Checks for existing attribute record
1622+ *
1623+ * @param string $table
1624+ * @param array $attributeData
1625+ * @return string
1626+ */
1627+ protected function checkExistingAttributeValue (string $ table , array $ attributeData ): string
1628+ {
1629+ $ connection = $ this ->getConnection ();
1630+ $ where = [];
1631+ unset($ attributeData ['value ' ]);
1632+
1633+ foreach ($ attributeData as $ key => $ val ) {
1634+ $ where [] = sprintf ('%s = :%s ' , $ key , $ key );
1635+ }
1636+ $ select = $ connection ->select ()->from ($ table , 'value_id ' )->where (implode (' AND ' , $ where ));
1637+
1638+ return $ connection ->fetchOne ($ select , $ attributeData );
1639+ }
1640+
16301641 /**
16311642 * Prepare value for save
16321643 *
0 commit comments