-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Issue] fix: adjustCreditMemoItemQuantities causes a fatal error on missing order/invoice #40790
Copy link
Copy link
Open
Labels
Area: OrderComponent: Order gridIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.8-p4Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branch
Metadata
Metadata
Assignees
Labels
Area: OrderComponent: Order gridIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.A defect with this priority could have functionality issues which are not to expectations.Reported on 2.4.8-p4Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branch
Type
Fields
Give feedbackNo fields configured for issues without a type.
Projects
StatusShow more project fields
Ready for Development
This issue is automatically created based on existing pull request: #40787: fix: adjustCreditMemoItemQuantities causes a fatal error on missing order/invoice
Preconditions and environment
order_id,creditmemo_id, orinvoice_idis passed to the credit memo save actionSteps to reproduce
order_id/creditmemo_idparameter (e.g. via a stale or manipulated POST request toadmin/sales/order_creditmemo/save).Expected result
The controller handles the failed credit memo load gracefully and redirects to the
noroutepage (or back with an appropriate error), without throwing a fatal error.Actual result
A
TypeErroris thrown and logged as aCRITICALerror, crashing the request:Additional information
Root cause: In
Save::execute(),adjustCreditMemoItemQuantities($creditmemo)is called on line 94 before theif ($creditmemo)guard on line 95. WhenCreditmemoLoader::load()returnsfalse, the typed method receivesfalseinstead of aCreditmemoinstance, triggering theTypeError.Fix: Move the
adjustCreditMemoItemQuantities($creditmemo)call inside theif ($creditmemo)block so it is only invoked when a valid credit memo object has been loaded.Release note
Fixed a
TypeErrorcrash in the admin credit memo save controller (Magento\Sales\Controller\Adminhtml\Order\Creditmemo\Save) that occurred when the credit memo could not be loaded. TheadjustCreditMemoItemQuantitiescall is now correctly guarded by the existingif ($creditmemo)check.