magento2: Order is not complete when mixing virtual, refunded and shipped items

Preconditions and environment

  • Magento 2.4.4-p7

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

  • 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)

Most upvoted comments

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

Let’s take the case below:

  • Create an order containing: 1 physical item of quantity = 2 (NO VIRTUAL ITEM)
  • Invoice the order
  • Refund 1 quantity of the physical item
  • Ship 1 quantity of the physical item

image

In that case, the order becomes Complete:

image

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

  • Create an order containing: 1 virtual item of quantity = 5 (NO PHYSICAL ITEM)
  • Invoice the order

image

The order is complete as well.

image

Knowing that, combination of both should be complete too.

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