@@ -181,9 +181,10 @@ protected function _prepareLoadSelect(array $selects)
181
181
* @param \Magento\Catalog\Model\AbstractModel $object
182
182
* @param AbstractAttribute $attribute
183
183
* @param mixed $value
184
+ * @param int|null $valueId
184
185
* @return $this
185
186
*/
186
- protected function _saveAttributeValue ($ object , $ attribute , $ value )
187
+ protected function _saveAttributeValue ($ object , $ attribute , $ value, $ valueId = null )
187
188
{
188
189
$ connection = $ this ->getConnection ();
189
190
$ hasSingleStore = $ this ->_storeManager ->hasSingleStore ();
@@ -213,14 +214,27 @@ protected function _saveAttributeValue($object, $attribute, $value)
213
214
);
214
215
}
215
216
216
- $ data = new \Magento \Framework \DataObject (
217
- [
218
- 'attribute_id ' => $ attribute ->getAttributeId (),
219
- 'store_id ' => $ storeId ,
220
- $ entityIdField => $ object ->getData ($ entityIdField ),
221
- 'value ' => $ this ->_prepareValueForSave ($ value , $ attribute ),
222
- ]
223
- );
217
+ if ($ valueId > 0 ) {
218
+ $ data = new \Magento \Framework \DataObject (
219
+ [
220
+ 'value_id ' => $ valueId ,
221
+ 'attribute_id ' => $ attribute ->getAttributeId (),
222
+ 'store_id ' => $ storeId ,
223
+ $ entityIdField => $ object ->getData ($ entityIdField ),
224
+ 'value ' => $ this ->_prepareValueForSave ($ value , $ attribute ),
225
+ ]
226
+ );
227
+ } else {
228
+ $ data = new \Magento \Framework \DataObject (
229
+ [
230
+ 'attribute_id ' => $ attribute ->getAttributeId (),
231
+ 'store_id ' => $ storeId ,
232
+ $ entityIdField => $ object ->getData ($ entityIdField ),
233
+ 'value ' => $ this ->_prepareValueForSave ($ value , $ attribute ),
234
+ ]
235
+ );
236
+ }
237
+
224
238
$ bind = $ this ->_prepareDataForTable ($ data , $ table );
225
239
226
240
if ($ attribute ->isScopeStore ()) {
@@ -325,15 +339,7 @@ protected function _insertAttribute($object, $attribute, $value)
325
339
*/
326
340
protected function _updateAttribute ($ object , $ attribute , $ valueId , $ value )
327
341
{
328
- $ table = $ attribute ->getBackend ()->getTable ();
329
- $ connection = $ this ->getConnection ();
330
- $ connection ->update (
331
- $ table ,
332
- ['value ' => $ this ->_prepareValueForSave ($ value , $ attribute )],
333
- sprintf ('%s=%d ' , $ connection ->quoteIdentifier ('value_id ' ), $ valueId )
334
- );
335
-
336
- return $ this ;
342
+ return $ this ->_saveAttributeValue ($ object , $ attribute , $ value , $ valueId );
337
343
}
338
344
339
345
/**
0 commit comments