@@ -39,7 +39,8 @@ public function check(Order $order)
39
39
$ order ->setState (Order::STATE_CLOSED )
40
40
->setStatus ($ order ->getConfig ()->getStateDefaultStatus (Order::STATE_CLOSED ));
41
41
} elseif ($ currentState === Order::STATE_PROCESSING
42
- && (!$ order ->canShip () || $ this ->isPartiallyRefundedOrderShipped ($ order ))
42
+ && (!$ order ->canShip () ||
43
+ ($ this ->isPartiallyRefundedOrderShipped ($ order ) && !$ this ->hasPendingShipmentItems ($ order )))
43
44
) {
44
45
$ order ->setState (Order::STATE_COMPLETE )
45
46
->setStatus ($ order ->getConfig ()->getStateDefaultStatus (Order::STATE_COMPLETE ));
@@ -58,6 +59,7 @@ public function check(Order $order)
58
59
*/
59
60
public function isPartiallyRefundedOrderShipped (Order $ order ): bool
60
61
{
62
+ //we should also check the number of items that require shipping
61
63
$ isPartiallyRefundedOrderShipped = false ;
62
64
if ($ this ->getShippedItems ($ order ) > 0
63
65
&& $ order ->getTotalQtyOrdered () <= $ this ->getRefundedItems ($ order ) + $ this ->getShippedItems ($ order )) {
@@ -67,6 +69,23 @@ public function isPartiallyRefundedOrderShipped(Order $order): bool
67
69
return $ isPartiallyRefundedOrderShipped ;
68
70
}
69
71
72
+ /**
73
+ * Check if order has items that haven't been shipped yet
74
+ *
75
+ * @param Order $order
76
+ * @return bool
77
+ */
78
+ private function hasPendingShipmentItems (Order $ order ): bool
79
+ {
80
+ foreach ($ order ->getAllItems () as $ item ) {
81
+ if ($ item ->canShip ()) {
82
+ return true ;
83
+ }
84
+ }
85
+
86
+ return false ;
87
+ }
88
+
70
89
/**
71
90
* Get all refunded items number
72
91
*
0 commit comments