Skip to content

Commit 612f1ae

Browse files
committed
ACP2E-2756: [Cloud] Order Status changed to complete when partially refund of a partially shipped order
- when creating a credit memo, order should not be set to completed if it is still has items that haven't been shipped yet
1 parent 881ca23 commit 612f1ae

File tree

1 file changed

+20
-1
lines changed
  • app/code/Magento/Sales/Model/ResourceModel/Order/Handler

1 file changed

+20
-1
lines changed

app/code/Magento/Sales/Model/ResourceModel/Order/Handler/State.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function check(Order $order)
3939
$order->setState(Order::STATE_CLOSED)
4040
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CLOSED));
4141
} elseif ($currentState === Order::STATE_PROCESSING
42-
&& (!$order->canShip() || $this->isPartiallyRefundedOrderShipped($order))
42+
&& (!$order->canShip() ||
43+
($this->isPartiallyRefundedOrderShipped($order) && !$this->hasPendingShipmentItems($order)))
4344
) {
4445
$order->setState(Order::STATE_COMPLETE)
4546
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_COMPLETE));
@@ -58,6 +59,7 @@ public function check(Order $order)
5859
*/
5960
public function isPartiallyRefundedOrderShipped(Order $order): bool
6061
{
62+
//we should also check the number of items that require shipping
6163
$isPartiallyRefundedOrderShipped = false;
6264
if ($this->getShippedItems($order) > 0
6365
&& $order->getTotalQtyOrdered() <= $this->getRefundedItems($order) + $this->getShippedItems($order)) {
@@ -67,6 +69,23 @@ public function isPartiallyRefundedOrderShipped(Order $order): bool
6769
return $isPartiallyRefundedOrderShipped;
6870
}
6971

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+
7089
/**
7190
* Get all refunded items number
7291
*

0 commit comments

Comments
 (0)