Skip to content

Commit 71ad851

Browse files
committed
ACP2E-1522: Auto increment number jumping up for catalog_product_entity_* tables
- Fixed the build error.
1 parent cb4e085 commit 71ad851

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,6 @@ protected function _saveAttributeValue($object, $attribute, $value)
221221
'value' => $this->_prepareValueForSave($value, $attribute),
222222
]
223223
);
224-
225-
$entity = $attribute->getEntity();
226-
$row = $this->getAttributeRow($entity, $object, $attribute);
227-
$whereArr = [];
228-
foreach ($row as $field => $value) {
229-
$whereArr[] = $connection->quoteInto($field . '=?', $value);
230-
}
231-
$where = implode(' AND ', $whereArr);
232-
$select = $connection->select()->from($table, ['value_id', 'value', 'store_id'])->where($where);
233-
$origRow = $connection->fetchRow($select);
234-
$origValueId = $origRow['value_id'] ?? false;
235-
$origStoreId = (int) $origRow['store_id'] ?? 0;
236-
$storeIds = $this->_storeManager->getStore($storeId)->getWebsite()->getStoreIds(true);
237-
238-
if ($origValueId > 0 && count($storeIds) === 1) {
239-
$data->setData('value_id', $origValueId);
240-
if ($storeId !== $origStoreId) {
241-
$data->setData('store_id', $origStoreId);
242-
}
243-
}
244-
245224
$bind = $this->_prepareDataForTable($data, $table);
246225

247226
if ($attribute->isScopeStore()) {
@@ -253,6 +232,7 @@ protected function _saveAttributeValue($object, $attribute, $value)
253232
/**
254233
* Update attribute value for website
255234
*/
235+
$storeIds = $this->_storeManager->getStore($storeId)->getWebsite()->getStoreIds(true);
256236
foreach ($storeIds as $storeId) {
257237
$bind['store_id'] = (int) $storeId;
258238
$this->_attributeValuesToSave[$table][] = $bind;

app/code/Magento/Eav/Model/Entity/AbstractEntity.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)