From 0e35c3c83c1ba5180fa26ebcf0a4a5e698f7ce2d Mon Sep 17 00:00:00 2001 From: Marcin Frymark Date: Tue, 19 Aug 2025 17:39:14 +0200 Subject: [PATCH 1/2] Fix: order save updates only changed fields (#40147) --- app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php b/app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php index 19b17beb537dd..c8b5c29f4249a 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php +++ b/app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php @@ -174,7 +174,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) protected function updateObject(\Magento\Framework\Model\AbstractModel $object) { $condition = $this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $object->getId()); - $data = $this->_prepareDataForSave($object); + $data = $this->prepareDataForUpdate($object); unset($data[$this->getIdFieldName()]); if (count($data) > 0) { $this->getConnection()->update($this->getMainTable(), $data, $condition); From bdbd3cdeb5dc0407d77a6b2e3644a349f10a46d6 Mon Sep 17 00:00:00 2001 From: Marcin Frymark Date: Wed, 20 Aug 2025 11:40:32 +0200 Subject: [PATCH 2/2] [Unit Tests] Update unit tests for fix-issue-40147 --- .../Unit/Model/ResourceModel/Order/Creditmemo/CommentTest.php | 1 + .../Test/Unit/Model/ResourceModel/Order/Invoice/CommentTest.php | 1 + .../Test/Unit/Model/ResourceModel/Order/Shipment/CommentTest.php | 1 + 3 files changed, 3 insertions(+) diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Creditmemo/CommentTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Creditmemo/CommentTest.php index 3698ffa4998ee..9b30b8f423b01 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Creditmemo/CommentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Creditmemo/CommentTest.php @@ -93,6 +93,7 @@ protected function setUp(): void ->method('lastInsertId'); $this->commentModelMock->expects($this->any())->method('hasDataChanges')->willReturn(true); $this->commentModelMock->expects($this->any())->method('isSaveAllowed')->willReturn(true); + $this->commentModelMock->expects($this->any())->method('getStoredData')->willReturn([]); $relationProcessorMock = $this->createMock( ObjectRelationProcessor::class diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Invoice/CommentTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Invoice/CommentTest.php index a6d399f2ad78d..7882f215f84b5 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Invoice/CommentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Invoice/CommentTest.php @@ -91,6 +91,7 @@ protected function setUp(): void ->method('lastInsertId'); $this->commentModelMock->expects($this->any())->method('hasDataChanges')->willReturn(true); $this->commentModelMock->expects($this->any())->method('isSaveAllowed')->willReturn(true); + $this->commentModelMock->expects($this->any())->method('getStoredData')->willReturn([]); $relationProcessorMock = $this->createMock( ObjectRelationProcessor::class diff --git a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/CommentTest.php b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/CommentTest.php index ea4daef2c1340..3d40b0ab5aaf4 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/CommentTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/CommentTest.php @@ -92,6 +92,7 @@ protected function setUp(): void ->method('lastInsertId'); $this->commentModelMock->expects($this->any())->method('hasDataChanges')->willReturn(true); $this->commentModelMock->expects($this->any())->method('isSaveAllowed')->willReturn(true); + $this->commentModelMock->expects($this->any())->method('getStoredData')->willReturn([]); $relationProcessorMock = $this->createMock( ObjectRelationProcessor::class