magento2: Order is not complete when mixing virtual, refunded and shipped items
Preconditions and environment
- Magento 2.4.4-p7
Steps to reproduce
- Create an order containing: 1 physical item of quantity = 2 and 1 virtual item of quantity = 5
- Invoice the order
- Refund 1 quantity of the physical item
- Ship 1 quantity of the physical item
Expected result
Order state should be complete.
Actual result
Order state is still processing.
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
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: open
- Created 3 months ago
- Reactions: 1
- Comments: 19 (7 by maintainers)
@engcom-Bravo it’s not consistent with the rest of Magento behavior then.
Let’s take the case below:
In that case, the order becomes Complete:
On top of that if you create another order like this:
The order is complete as well.
Knowing that, combination of both should be complete too.
Confirming the issue is present in 2.4-develop, screenshots below from the instance above:
