Skip to content

Commit 00ac183

Browse files
committed
ACP2E-3361: Some of the relations records are saved to DB when order record is saved
1 parent 0f7cce0 commit 00ac183

File tree

1 file changed

+14
-7
lines changed
  • lib/internal/Magento/Framework/Model/ResourceModel/Db/VersionControl

1 file changed

+14
-7
lines changed

lib/internal/Magento/Framework/Model/ResourceModel/Db/VersionControl/Snapshot.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public function __construct(
3939
/**
4040
* Register snapshot of entity data, for tracking changes
4141
*
42-
* @param \Magento\Framework\DataObject $entity
42+
* @param DataObject $entity
4343
* @return void
4444
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
4545
*/
46-
public function registerSnapshot(\Magento\Framework\DataObject $entity)
46+
public function registerSnapshot(DataObject $entity)
4747
{
4848
$metaData = $this->metadata->getFields($entity);
4949
$filteredData = array_intersect_key($entity->getData(), $metaData);
@@ -72,10 +72,10 @@ public function getSnapshotData(DataObject $entity): array
7272
/**
7373
* Check is current entity has changes, by comparing current object state with stored snapshot
7474
*
75-
* @param \Magento\Framework\DataObject $entity
75+
* @param DataObject $entity
7676
* @return bool
7777
*/
78-
public function isModified(\Magento\Framework\DataObject $entity)
78+
public function isModified(DataObject $entity): bool
7979
{
8080
if (!$entity->getId()) {
8181
return true;
@@ -86,7 +86,14 @@ public function isModified(\Magento\Framework\DataObject $entity)
8686
return true;
8787
}
8888
foreach ($this->snapshotData[$entityClass][$entity->getId()] as $field => $value) {
89-
if ($entity->getDataByKey($field) != $value) {
89+
$entityValue = $entity->getDataByKey($field);
90+
if (is_array($entityValue) && is_string($value)) {
91+
$decodedValue = json_decode($value, true);
92+
if (json_last_error() === JSON_ERROR_NONE) {
93+
$value = $decodedValue;
94+
}
95+
}
96+
if ($entityValue != $value) {
9097
return true;
9198
}
9299
}
@@ -97,9 +104,9 @@ public function isModified(\Magento\Framework\DataObject $entity)
97104
/**
98105
* Clear snapshot data
99106
*
100-
* @param \Magento\Framework\DataObject|null $entity
107+
* @param DataObject|null $entity
101108
*/
102-
public function clear(\Magento\Framework\DataObject $entity = null)
109+
public function clear(DataObject $entity = null)
103110
{
104111
if ($entity !== null) {
105112
$this->snapshotData[get_class($entity)] = [];

0 commit comments

Comments
 (0)