Skip to content

Commit 2fdb50e

Browse files
committed
ACP2E-1522: Auto increment number jumping up for catalog_product_entity_* tables
- Fixed the build error.
1 parent 32f43b7 commit 2fdb50e

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

app/code/Magento/Catalog/Model/ResourceModel/AbstractResource.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ protected function _prepareLoadSelect(array $selects)
181181
* @param \Magento\Catalog\Model\AbstractModel $object
182182
* @param AbstractAttribute $attribute
183183
* @param mixed $value
184+
* @param int|null $valueId
184185
* @return $this
185186
*/
186-
protected function _saveAttributeValue($object, $attribute, $value)
187+
protected function _saveAttributeValue($object, $attribute, $value, $valueId = null)
187188
{
188189
$connection = $this->getConnection();
189190
$hasSingleStore = $this->_storeManager->hasSingleStore();
@@ -213,14 +214,27 @@ protected function _saveAttributeValue($object, $attribute, $value)
213214
);
214215
}
215216

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+
224238
$bind = $this->_prepareDataForTable($data, $table);
225239

226240
if ($attribute->isScopeStore()) {
@@ -325,15 +339,7 @@ protected function _insertAttribute($object, $attribute, $value)
325339
*/
326340
protected function _updateAttribute($object, $attribute, $valueId, $value)
327341
{
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);
337343
}
338344

339345
/**

0 commit comments

Comments
 (0)