-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Invoice addComment can throw error when Invoice getComments is called first #39884
Copy link
Copy link
Closed
Closed
Copy link
Labels
Area: OrderComponent: SalesIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.May be fixed according to the position in the backlog.Progress: PR CreatedIndicates that Pull Request has been created to fix issueIndicates that Pull Request has been created to fix issueProgress: doneReported on 2.4.8Indicates original Magento version for the Issue report.Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
Metadata
Metadata
Assignees
Labels
Area: OrderComponent: SalesIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.May be fixed according to the position in the backlog.Progress: PR CreatedIndicates that Pull Request has been created to fix issueIndicates that Pull Request has been created to fix issueProgress: doneReported on 2.4.8Indicates original Magento version for the Issue report.Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject itIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
Preconditions and environment
The Invoice model
module-sales/Model/Order/Invoice.phpcan return both a collection or an array. If the invoice object has the 'comments' data key, it will just return it, regardless of it being sometimes an array, like when$invoice->getComments()was called before attempting to add a comment. One reason for this would be that bothgetComments()andgetCommentsCollection()are using the sameInvoiceInterface::COMMENTSdata key to get/set data, but using different data types (array vs collection) to populate it.Example to replicate:
So a call to
$invoice->addComment()is causingError: Call to a member function addItem() on array in /var/www/html/vendor/magento/module-sales/Model/Order/Invoice.php:716.Comparing
getCommentsCollection()method between Invoice and CreditMemo models, reveals the different implementation.For the above example, adding
$invoice->unsetData(InvoiceInterface::COMMENTS);right before theaddCommentcall, will make it work, because due to not having the comments key will makegetCommentsCollection()return a proper collection.Affected versions: 2.4.7, 2.4.8 (I've only checked and confirmed the code issue on these versions)
Steps to reproduce
Implement the following sequence in a custom module:
Expected result
Comment is added to the invoice
Actual result
Error: Call to a member function addItem() on array in /var/www/html/vendor/magento/module-sales/Model/Order/Invoice.php:716Additional information
No response
Release note
No response
Triage and priority