-
Notifications
You must be signed in to change notification settings - Fork 9.4k
#23440 fix Refund for bundle product without receiving product back e… #27455
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
#23440 fix Refund for bundle product without receiving product back e… #27455
Conversation
Hi @KiuNguyen. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
@magento give me 2.4-develop instance |
Hi @KiuNguyen. Thank you for your request. I'm working on Magento 2.4-develop instance for you |
Hi @KiuNguyen, here is your Magento instance. |
@magento give me test instance |
Hi @KiuNguyen. Thank you for your request. I'm working on Magento instance for you |
Hi @KiuNguyen, here is your new Magento instance. |
@magento give me test instance |
Hi @nuzil. Thank you for your request. I'm working on Magento instance for you |
@magento give me test instance |
Hi @nuzil. Thank you for your request. I'm working on Magento instance for you |
Hi @nuzil, here is your new Magento instance. |
@@ -147,7 +147,7 @@ protected function canRefundItem($item, $qtys = [], $invoiceQtysRefundLimits = [ | |||
if ($item->isDummy()) { | |||
if ($item->getHasChildren()) { | |||
foreach ($item->getChildrenItems() as $child) { | |||
if (empty($qtys)) { | |||
if (empty($qtys) || (count(array_unique($qtys)) === 1 && end($qtys) == 0)) { |
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.
Any particular reason why you do not want to make === compare?
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 @nuzil
Any particular reason why you do not want to make === compare?
When I debug, I saw $qtys will return array value like this:
array (size=3)
48 => string '0' (length=1)
49 => string '0' (length=1)
50 => string '0' (length=1)
So now I already update code to use === compare
if (empty($qtys) || (count(array_unique($qtys)) === 1 && (int)end($qtys) === 0)) {
Please check this,
Thanks
… fixbug-23440-Refund-bundle-product-without-receiving-product-back-error
Hi @nuzil, thank you for the review. |
…thout-receiving-product-back-error
Hi @KiuNguyen, thank you for your contribution! |
@magento give me 2.4-develop instance |
Description (*)
Fix Refund for bundle product without receiving the product back getting error
Fixed Issues (if relevant)
Manual testing scenarios (*)
After click on update qty, bundle item not render and total refund amount is 25$

Create credit memo
Expected result (*)
Credit Memo for amount 25$ created
Actual result (*)
Error: "The most money available to refund is xx.xx.
Addition info:
After check issue, I saw this issue happen because the bundle item does not render in the form when all child product qty set to 0
Check function "canRefundItem" in Magento/Sales/Model/Order/CreditmemoFactory.php:145 When we create a refund for bundle product with all item qty = 0
if ($item->getHasChildren()) { foreach ($item->getChildrenItems() as $child) { if (empty($qtys)) { if ($this->canRefundNoDummyItem($child, $invoiceQtysRefundLimits)) { return true; } } else { if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) { return true; } } } return false; }
The return value will return false and exclude bundle parent item in return result
=> bundle parent item does not render in Magento/Sales/view/adminhtml/templates/order/creditmemo/create/items.phtml

So the qty value for each item not exist
If the bundle item does not render in credit memo page and we create a credit memo, so when the function "createByOrder" to be call, the problem happen:
Magento/Sales/Model/Order/CreditmemoFactory.php:69
$qtyList = isset($data['qtys']) ? $data['qtys'] : [];
$qtyList now is an empty array, but in this case, it should have data contain item_id with qty = 0
So this function will get all available refund qty for each item => the root of issue:
If credit memo doesn't have adjustment amount, it will create credit memo for all item of bundle product (even we already updated all item qty to 0 - STEP 5 )
If credit memo have adjustment amount, the error message will show: "The most money available to refund is xxxx"
I have pushed the commit to fix this issue
After apply update code, when we update qty for all bundle item to 0, the bundle item will show correctly:
Result after create credit memo:
Contribution checklist (*)