-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix type error for item qty when refunding an invoice #40303
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
base: 2.4-develop
Are you sure you want to change the base?
Fix type error for item qty when refunding an invoice #40303
Conversation
|
Hi @mfickers. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
|
Hi @mfickers, I have a question: in the ticket and on your first screenshot the error is related to the \Magento\Sales\Model\Order\Creditmemo\Validation\QuantityValidator::isValidDecimalRefundQty() method. |
|
Basically
I feel like the code in the That is why I fixed it in the Factory instead of the Validator. |
swnsma
left a comment
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.
Hi @mfickers,
Thank you for the explanation!
Yes please, I see much sense of adding type casting to the \Magento\Sales\Model\Order\Creditmemo\Validation\QuantityValidator as well.
According to the definition of done I also need to ask you to cover this change with tests.
Could you extend an unit test to cover this explicit case with type casting? Thank you.
6f10e2a to
15e71b1
Compare
|
I've added type casting to the QuantityValidator to make sure type errors regarding CreditmemoItem qty don't happen anymore. I've also added a test case for the QuantityValidatorTest where OrderItem and CreditmemoItem qtys are both |
|
@magento run all tests |

Description (*)
When

minis called with different types, there is no defined behavior which result is returned. When using theinvoice/<invoice_id>/refundREST API endpoint, this might cause a type error:This PR casts the invoice item quantity to
floatto prevent the type error.Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
invoice/invoice_id/refundand refund the item with qty 1Depending on the configuration of the PHP environment, you might need to reorder the arguments provided to

minat app/code/Magento/Sales/Model/Order/CreditmemoFactory.php:139 to be able to reproduce:Note that
$qtyis typestring, when it should befloat.Questions or comments
Contribution checklist (*)