New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MC-13180: Fetching invoice items with \Magento\Sales\Model\Order\Invoice getItems function sometimes returns a collection #27345
base: 2.4-develop
Are you sure you want to change the base?
Conversation
Hi @AleksLi. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import class, fix the static tests 😀
Instead of changing the whole Interface, just return the array of Items. This is least backwards-incompatible way to achieve your goal.
@lbajsarowicz I was trying to resolve this another way but the logic here was constructed to return Simply returning an array as that's written in the code won't make it work. I debugged the issue for several hours trying to resolve it in an easy way. Of course, method getItems() should return InvoiceItemInterface[] as it expected, but we should change everything connected to that. As you know that would affect other modules I guess and affect 3rd party modules. Your suggestion? |
@lbajsarowicz hello. Could you suggest any possible solution for that? How to do it appropriately? |
Changing This will, of course, be a breaking change, but only for people who depended on the unpublished interface (hacked). Anything else I missed? |
@antonkril thanks for your influence. Let me try to understand and try to apply your thought. |
@@ -502,7 +502,7 @@ public function getItemsCollection() | |||
} | |||
} | |||
} | |||
return $this->getItems(); | |||
return $this->getData(InvoiceInterface::ITEMS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antonkril Here is what I changed here.
Could you check this and tell me about getItems() method. I guess nothing should be changed there? Or I misunderstand something about your comment "Changing getItems() to hashmap .. "
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getItems
is in the title of the issue, so we need to unify its behavior. Also, we need to modify getItemsCollectionX
to not setItems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, but what would be the behavior of the method getItemsCollection in this case? Of course, it should return ItemsCollection as expected from the name. As Collection is iterable it will contain the items? But items could be empty and what to return in that case?
$this->setItems($this->_invoiceItemCollectionFactory->create()->setInvoiceFilter($this->getId())); | ||
|
||
if ($this->getId()) { | ||
foreach ($this->getItems() as $item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antonkril what if getItemsCollection would return only the collection as it expected from the name of the method?
… condition to get items when they required.
…instead of getItems() method.
… only. GetItems method won't take place here.
Hi @AleksLi I have applied the latest changes in this PR and notice an issue when creating an invoice from at least the backend:
Apparently this change is breaking this code: This is because $this->getId in the method getItems() returns null at this point: A workaround could be calling getAllItems or getItemsCollection, but I'm uncertain sure of the impact. Also which other areas might also be affected by this? This all feels a bit like a can of worms. |
Hi, is there any plan to continue working on this and merge it? |
Hi, |
Description (*)
Created an example of the solution. I think something like this would fix the issue since it is using a lot in the process of adding Item.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Well explained in the description of #13180
Questions or comments
Contribution checklist (*)