@@ -1669,6 +1669,7 @@ protected function _deleteAttributes($object, $table, $info)
16691669 */
16701670 public function saveAttribute (DataObject $ object , $ attributeCode )
16711671 {
1672+ $ updateValue = 0 ;
16721673 $ attribute = $ this ->getAttribute ($ attributeCode );
16731674 $ backend = $ attribute ->getBackend ();
16741675 $ table = $ backend ->getTable ();
@@ -1699,10 +1700,15 @@ public function saveAttribute(DataObject $object, $attributeCode)
16991700 $ this ->_insertAttribute ($ object , $ attribute , $ newValue );
17001701 } elseif ($ origValueId !== false && $ newValue !== null ) {
17011702 $ this ->_updateAttribute ($ object , $ attribute , $ origValueId , $ newValue );
1703+ $ updateValue = 1 ;
17021704 } elseif ($ origValueId !== false && $ newValue === null && $ origValue !== null ) {
17031705 $ connection ->delete ($ table , $ where );
17041706 }
1705- $ this ->_processAttributeValues ();
1707+ if ($ updateValue === 1 ) {
1708+ $ this ->_updateAttributeValues ($ attribute , $ origValueId );
1709+ } else {
1710+ $ this ->_processAttributeValues ();
1711+ }
17061712 $ connection ->commit ();
17071713 } catch (\Exception $ e ) {
17081714 $ connection ->rollBack ();
@@ -2011,4 +2017,32 @@ protected function loadAttributesForObject($attributes, $object = null)
20112017 }
20122018 }
20132019 }
2020+
2021+ /**
2022+ * Update entity attribute values
2023+ *
2024+ * @param AbstractAttribute $attribute
2025+ * @param mixed $valueId
2026+ * @return $this
2027+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
2028+ */
2029+ protected function _updateAttributeValues (AbstractAttribute $ attribute , mixed $ valueId ): static
2030+ {
2031+ $ connection = $ this ->getConnection ();
2032+ foreach ($ this ->_attributeValuesToSave as $ table => $ data ) {
2033+ foreach ($ data as $ columnValue ) {
2034+ $ connection ->update (
2035+ $ table ,
2036+ ['value ' => $ this ->_prepareValueForSave ($ columnValue ['value ' ], $ attribute )],
2037+ sprintf ('%s=%d ' , $ connection ->quoteIdentifier ('value_id ' ), $ valueId )
2038+ );
2039+ }
2040+ }
2041+
2042+ // reset data arrays
2043+ $ this ->_attributeValuesToSave = [];
2044+
2045+
2046+ return $ this ;
2047+ }
20142048}
0 commit comments