Skip to content

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

@digitalpianism

Description

@digitalpianism

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”.

Metadata

Metadata

Labels

Area: OrderComponent: order statusIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: PR in progressReported on 2.4.4-p7Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions