Skip to content

Commit 6c7c318

Browse files
committed
MAGETWO-54658: Order status change after Invoice creation through API
1 parent 23abedc commit 6c7c318

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

app/code/Magento/Sales/Model/Order/StateResolver.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,48 @@
1313
*/
1414
class StateResolver implements OrderStateResolverInterface
1515
{
16-
1716
/**
18-
* Check is order in complete state
17+
* Check if order should be in complete state
1918
*
2019
* @param OrderInterface $order
2120
* @return bool
2221
*/
23-
private function checkIsOrderComplete(OrderInterface $order)
22+
private function isOrderComplete(OrderInterface $order)
2423
{
25-
/** @var $order Order|OrderInterface */
24+
/** @var $order Order|OrderInterface */
2625
if (0 == $order->getBaseGrandTotal() || $order->canCreditmemo()) {
27-
if ($order->getState() !== Order::STATE_COMPLETE) {
28-
return true;
29-
}
26+
return true;
3027
}
3128
return false;
3229
}
3330

3431
/**
35-
* Check is order in cancel state
32+
* Check if order should be in closed state
3633
*
3734
* @param OrderInterface $order
3835
* @param array $arguments
3936
* @return bool
4037
*/
41-
private function checkIsOrderClosed(OrderInterface $order, $arguments)
38+
private function isOrderClosed(OrderInterface $order, $arguments)
4239
{
43-
/** @var $order Order|OrderInterface */
40+
/** @var $order Order|OrderInterface */
4441
$forceCreditmemo = in_array(self::FORCED_CREDITMEMO, $arguments);
4542
if (floatval($order->getTotalRefunded()) || !$order->getTotalRefunded() && $forceCreditmemo) {
46-
if ($order->getState() !== Order::STATE_CLOSED) {
47-
return true;
48-
}
43+
return true;
4944
}
5045
return false;
5146
}
5247

5348
/**
54-
* Check is order in cancel state
49+
* Check if order is processing
5550
*
5651
* @param OrderInterface $order
5752
* @param array $arguments
5853
* @return bool
5954
*/
60-
private function checkIsOrderProcessing(OrderInterface $order, $arguments)
55+
private function isOrderProcessing(OrderInterface $order, $arguments)
6156
{
62-
/** @var $order Order|OrderInterface */
57+
/** @var $order Order|OrderInterface */
6358
if ($order->getState() == Order::STATE_NEW && in_array(self::IN_PROGRESS, $arguments)) {
6459
return true;
6560
}
@@ -84,16 +79,16 @@ private function getInitialOrderState(OrderInterface $order)
8479
*/
8580
public function getStateForOrder(OrderInterface $order, array $arguments = [])
8681
{
87-
/** @var $order Order|OrderInterface */
82+
/** @var $order Order|OrderInterface */
8883
$orderState = $this->getInitialOrderState($order);
8984
if (!$order->isCanceled() && !$order->canUnhold() && !$order->canInvoice() && !$order->canShip()) {
90-
if ($this->checkIsOrderComplete($order)) {
85+
if ($this->isOrderComplete($order)) {
9186
$orderState = Order::STATE_COMPLETE;
92-
} elseif ($this->checkIsOrderClosed($order, $arguments)) {
87+
} elseif ($this->isOrderClosed($order, $arguments)) {
9388
$orderState = Order::STATE_CLOSED;
9489
}
9590
}
96-
if ($this->checkIsOrderProcessing($order, $arguments)) {
91+
if ($this->isOrderProcessing($order, $arguments)) {
9792
$orderState = Order::STATE_PROCESSING;
9893
}
9994
return $orderState;

app/code/Magento/Sales/Model/OrderInvoice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function execute(
138138
InvoiceCommentCreationInterface $comment = null,
139139
InvoiceCreationArgumentsInterface $arguments = null
140140
) {
141-
$connection = $this->resourceConnection->getConnectionByName('sales');
141+
$connection = $this->resourceConnection->getConnection('sales');
142142
$order = $this->orderRepository->get($orderId);
143143
$invoice = $this->invoiceDocumentFactory->create(
144144
$order,

app/code/Magento/Sales/Test/Unit/Model/OrderInvoiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function setUp()
192192
public function testOrderInvoice($orderId, $capture, $items, $notify, $appendComment)
193193
{
194194
$this->resourceConnectionMock->expects($this->once())
195-
->method('getConnectionByName')
195+
->method('getConnection')
196196
->with('sales')
197197
->willReturn($this->adapterInterface);
198198

@@ -336,7 +336,7 @@ public function testCouldNotInvoiceException()
336336
$notify = true;
337337
$appendComment = true;
338338
$this->resourceConnectionMock->expects($this->once())
339-
->method('getConnectionByName')
339+
->method('getConnection')
340340
->with('sales')
341341
->willReturn($this->adapterInterface);
342342

0 commit comments

Comments
 (0)