File tree Expand file tree Collapse file tree 2 files changed +40
-4
lines changed
Model/ResourceModel/Order/Handler
Test/Unit/Model/ResourceModel/Order/Handler Expand file tree Collapse file tree 2 files changed +40
-4
lines changed Original file line number Diff line number Diff line change 7
7
namespace Magento \Sales \Model \ResourceModel \Order \Handler ;
8
8
9
9
use Magento \Sales \Model \Order ;
10
+ use Magento \Sales \Model \Order \Invoice ;
10
11
11
12
/**
12
13
* Checking order status and adjusting order status before saving
@@ -27,7 +28,11 @@ public function check(Order $order)
27
28
->setStatus ($ order ->getConfig ()->getStateDefaultStatus (Order::STATE_PROCESSING ));
28
29
$ currentState = Order::STATE_PROCESSING ;
29
30
}
30
- if ($ order ->isCanceled () || $ order ->canUnhold () || $ order ->canInvoice ()) {
31
+ if ($ order ->isCanceled () ||
32
+ $ order ->canUnhold () ||
33
+ $ order ->canInvoice () ||
34
+ ($ this ->orderHasOpenInvoices ($ order ) && (int ) $ order ->getTotalDue () > 0 )
35
+ ) {
31
36
return $ this ;
32
37
}
33
38
@@ -62,6 +67,24 @@ private function checkForCompleteState(Order $order, ?string $currentState): boo
62
67
return false ;
63
68
}
64
69
70
+ /**
71
+ * Check if order has unpaid invoices
72
+ *
73
+ * @param Order $order
74
+ * @return bool
75
+ */
76
+ private function orderHasOpenInvoices (Order $ order ): bool
77
+ {
78
+ /** @var Invoice $invoice */
79
+ foreach ($ order ->getInvoiceCollection ()->getItems () as $ invoice ) {
80
+ if ($ invoice ->getState () == Invoice::STATE_OPEN ) {
81
+ return true ;
82
+ }
83
+ }
84
+
85
+ return false ;
86
+ }
87
+
65
88
/**
66
89
* Check if order can be automatically switched to closed state
67
90
*
Original file line number Diff line number Diff line change 8
8
namespace Magento \Sales \Test \Unit \Model \ResourceModel \Order \Handler ;
9
9
10
10
use Magento \Sales \Model \Order ;
11
- use Magento \Sales \Model \Order \Address ;
12
11
use Magento \Sales \Model \Order \Item ;
13
- use Magento \Sales \Model \ResourceModel \ Order \Address \ Collection ;
12
+ use Magento \Sales \Model \Order \Invoice ;
14
13
use Magento \Sales \Model \ResourceModel \Order \Handler \State ;
14
+ use Magento \Sales \Model \ResourceModel \Order \Invoice \Collection as InvoiceCollection ;
15
15
use PHPUnit \Framework \MockObject \MockObject ;
16
16
use PHPUnit \Framework \TestCase ;
17
17
@@ -47,14 +47,27 @@ protected function setUp(): void
47
47
'getIsNotVirtual ' ,
48
48
'getStatus ' ,
49
49
'getAllItems ' ,
50
- 'getTotalQtyOrdered '
50
+ 'getInvoiceCollection ' ,
51
+ 'getTotalQtyOrdered ' ,
52
+ 'getTotalDue '
51
53
]
52
54
)
53
55
->disableOriginalConstructor ()
54
56
->getMock ();
55
57
$ this ->orderMock ->expects ($ this ->any ())
56
58
->method ('getConfig ' )
57
59
->willReturnSelf ();
60
+ $ invoice = $ this ->createMock (Invoice::class);
61
+ $ invoice ->expects ($ this ->any ())
62
+ ->method ('getState ' )
63
+ ->willReturn (Invoice::STATE_PAID );
64
+ $ invoiceCollection = $ this ->createMock (InvoiceCollection::class);
65
+ $ invoiceCollection ->expects ($ this ->any ())
66
+ ->method ('getItems ' )
67
+ ->willReturn ([$ invoice ]);
68
+ $ this ->orderMock ->expects ($ this ->any ())
69
+ ->method ('getInvoiceCollection ' )
70
+ ->willReturn ($ invoiceCollection );
58
71
$ this ->state = new State ();
59
72
}
60
73
You can’t perform that action at this time.
0 commit comments