magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Order is not complete when mixing virtual, refunded and shipped items #38547

Open digitalpianism opened 7 months ago

digitalpianism commented 7 months ago

Preconditions and environment

Steps to reproduce

  1. Create an order containing: 1 physical item of quantity = 2 and 1 virtual item of quantity = 5
  2. Invoice the order
  3. Refund 1 quantity of the physical item
  4. Ship 1 quantity of the physical item

image

Expected result

Order state should be complete.

Actual result

Order state is still processing. image

Additional information

Problem comes from magento/module-sales/Model/ResourceModel/Order/Handler/State.php

In the isPartiallyRefundedOrderShipped, the code compares the total qty ordered with the sum of total qty shipped and total qty refunded.

However, virtual items are not considered when retrieving the total qty shipped, preventing the method from returning true.

Here's the fix that I have used to resolve the issue:

diff --git a/src/vendor/magento/module-sales/Model/ResourceModel/Order/Handler/State.php b/src/vendor/magento/module-sales/Model/ResourceModel/Order/Handler/State.php
index 51c45ed5e5..8d97ce01cb 100644
--- module-sales/Model/ResourceModel/Order/Handler/State.php
+++ module-sales/Model/ResourceModel/Order/Handler/State.php
@@ -97,1 +97,3 @@ class State
-            $numOfShippedItems += (int)$item->getQtyShipped();
+            $numOfShippedItems += $item->getIsVirtual()
+                ? (int)$item->getQtyOrdered()
+                : (int)$item->getQtyShipped();

Release note

No response

Triage and priority

m2-assistant[bot] commented 7 months ago

Hi @digitalpianism. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

digitalpianism commented 7 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 7 months ago

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

magento-deployment-service[bot] commented 7 months ago

Hi @digitalpianism, here is your Magento Instance: https://6fc1486a44c08bdcd128df01c88544ca.instances-prod.magento-community.engineering Admin access: https://6fc1486a44c08bdcd128df01c88544ca.instances-prod.magento-community.engineering/admin_b24a Login: 15429f36 Password: 18b19d16f0d9

digitalpianism commented 7 months ago

Confirming the issue is present in 2.4-develop, screenshots below from the instance above: image image

m2-assistant[bot] commented 7 months ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 7 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 7 months ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 7 months ago

Hi @engcom-Bravo, here is your Magento Instance: https://6fc1486a44c08bdcd128df01c88544ca.instances-prod.magento-community.engineering Admin access: https://6fc1486a44c08bdcd128df01c88544ca.instances-prod.magento-community.engineering/admin_2102 Login: dea1c8b9 Password: 65ecb079ce48

engcom-Bravo commented 7 months ago

Hi @digitalpianism,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is not reproducible.Kindly refer the screenshots.

Steps to reproduce

Screenshot 2024-03-25 at 11 16 09 Screenshot 2024-03-25 at 11 16 17

The order is still in Processing because we have one more quantity for the physical product to ship.

Could you please let us know if we are missing anything.

Thanks.

digitalpianism commented 7 months ago

@engcom-Bravo it's not consistent with the rest of Magento behavior then.

Let's take the case below:

image

In that case, the order becomes Complete:

image

On top of that if you create another order like this:

image

The order is complete as well.

image

Knowing that, combination of both should be complete too.

engcom-Bravo commented 7 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 7 months ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 7 months ago

Hi @engcom-Bravo, here is your Magento Instance: https://6fc1486a44c08bdcd128df01c88544ca.instances-prod.magento-community.engineering Admin access: https://6fc1486a44c08bdcd128df01c88544ca.instances-prod.magento-community.engineering/admin_a8e6 Login: 96ce0477 Password: a63125bbdf3c

engcom-Bravo commented 7 months ago

Hi @digitalpianism,

Thanks for your update.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.

The Order is still in Processing state when we have combination of both physical products and virtual products.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 7 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-11691 is successfully created for this GitHub issue.

m2-assistant[bot] commented 7 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

github-jira-sync-bot commented 7 months ago

:x: Cannot export the issue. This GitHub issue is already linked to Jira issue(s): https://jira.corp.adobe.com/browse/AC-11691

digitalrisedorset commented 6 months ago

@magento I am working on this

digitalrisedorset commented 6 months ago

@magento run all tests

digitalrisedorset commented 6 months ago

I have started to have some feedbacks for this issue and I will put a report on where we are at this point.

As a consequence, when a product has been refunded, it can overlap with the shipment data (in which case, using the tests to reproduce the issue, the order is expected to remain to processing) it can be separate from the shipment data, we refund an item that was not sent yet (the credit memo is expected to adjust the shipping fees to 0 in this case) and the order status would be expected to be set to complete

--> the conclusion of this finding is that unless we can flag is a refund is for a shipped item or not, then we can't change the order status to complete. --> the focus with this issue was to verify virtual items did not prevent the order to be set to complete if all the physical items in the order were handled by shipment or refund. But the fact we are not able to separate refund and shipment data leads us to be still at the original place.