Skip to content

#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

Conversation

KiuNguyen
Copy link
Contributor

@KiuNguyen KiuNguyen commented Mar 26, 2020

Description (*)

Fix Refund for bundle product without receiving the product back getting error

Fixed Issues (if relevant)

  1. Fixes Refund for bundle product without receiving product back #23440: Refund for bundle product without receiving product back

Manual testing scenarios (*)

  1. Create a bundle product with at least 2 products
  2. Create order with bundle product
  3. Invoice Order
  4. Shop Order
  5. Create Credit Memo without taking the product back in stock and only refund amount:
  • Change all qty to 0
  • Add adjustment refund: 10$
  • Click on button update qty

Screenshot - 2020-03-26T174254 117

  1. After click on update qty, bundle item not render and total refund amount is 25$
    Screenshot - 2020-03-26T174317 561

  2. Create credit memo

Expected result (*)
Credit Memo for amount 25$ created

Actual result (*)

Error: "The most money available to refund is xx.xx.

Screenshot - 2020-03-26T174352 267

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
Screenshot - 2020-03-26T174317 561

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:

Screenshot - 2020-03-26T182313 566

Result after create credit memo:

Screenshot - 2020-03-26T182334 431

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Mar 26, 2020

Hi @KiuNguyen. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@KiuNguyen
Copy link
Contributor Author

@magento give me 2.4-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @KiuNguyen. Thank you for your request. I'm working on Magento 2.4-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @KiuNguyen, here is your Magento instance.
Admin access: https://i-27455-2-4-develop.instances.magento-community.engineering/admin_ccb8
Login: 3a5ccf76 Password: d92ad8214142
Instance will be terminated in up to 3 hours.

@KiuNguyen
Copy link
Contributor Author

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @KiuNguyen. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @KiuNguyen, here is your new Magento instance.
Admin access: https://pr-27455.instances.magento-community.engineering/admin_75f2
Login: 16c77c8c Password: 20f715c3e072
Instance will be terminated in up to 3 hours.

@nuzil nuzil self-assigned this Mar 30, 2020
@nuzil
Copy link
Contributor

nuzil commented Mar 30, 2020

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @nuzil. Thank you for your request. I'm working on Magento instance for you

@nuzil
Copy link
Contributor

nuzil commented Mar 30, 2020

@magento give me test instance

@magento-engcom-team
Copy link
Contributor

Hi @nuzil. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @nuzil, here is your new Magento instance.
Admin access: https://pr-27455.instances.magento-community.engineering/admin_5563
Login: 08f7c973 Password: 3e0a69104ac8
Instance will be terminated in up to 3 hours.

@@ -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)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@nuzil nuzil added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Apr 20, 2020
@engcom-Echo engcom-Echo requested a review from nuzil April 28, 2020 10:23
@magento-engcom-team
Copy link
Contributor

Hi @nuzil, thank you for the review.
ENGCOM-7460 has been created to process this Pull Request

@engcom-Delta
Copy link
Contributor

✔️ QA passed
Result:
image

image

image

@slavvka slavvka linked an issue Apr 29, 2020 that may be closed by this pull request
@slavvka slavvka added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S1 Affects critical data or functionality and forces users to employ a workaround. labels Apr 29, 2020
@slavvka slavvka added this to the 2.4.1 milestone Apr 29, 2020
@sdzhepa sdzhepa added the QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope label May 14, 2020
slavvka added a commit that referenced this pull request May 15, 2020
@slavvka slavvka merged commit f7fafca into magento:2.4-develop May 15, 2020
@m2-assistant
Copy link

m2-assistant bot commented May 15, 2020

Hi @KiuNguyen, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@vinhan2020
Copy link

vinhan2020 commented May 8, 2021

@magento give me 2.4-develop instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Sales Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S1 Affects critical data or functionality and forces users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refund for bundle product without receiving product back
9 participants