Skip to content

Commit 9298e79

Browse files
author
Joan He
committed
MC-5570: Different Order Status of two created credit memo orders
1 parent ab52d4b commit 9298e79

File tree

2 files changed

+26
-29
lines changed
  • app/code/Magento/Sales

2 files changed

+26
-29
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class State
2424
public function check(Order $order)
2525
{
2626
$currentState = $order->getState();
27+
if ($currentState == Order::STATE_NEW && $order->getIsInProcess()) {
28+
$order->setState(Order::STATE_PROCESSING)
29+
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING));
30+
$currentState = Order::STATE_PROCESSING;
31+
}
32+
2733
if (!$order->isCanceled() && !$order->canUnhold() && !$order->canInvoice()) {
2834
if (in_array($currentState, [Order::STATE_PROCESSING, Order::STATE_COMPLETE]) && !$order->canCreditmemo()) {
2935
$order->setState(Order::STATE_CLOSED)
@@ -33,11 +39,6 @@ public function check(Order $order)
3339
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_COMPLETE));
3440
}
3541
}
36-
37-
if ($currentState == Order::STATE_NEW && $order->getIsInProcess()) {
38-
$order->setState(Order::STATE_PROCESSING)
39-
->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING));
40-
}
4142
return $this;
4243
}
4344
}

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Handler/StateTest.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ protected function setUp()
3737
'canShip',
3838
'getBaseGrandTotal',
3939
'canCreditmemo',
40-
'getState',
41-
'setState',
40+
// 'getState',
41+
// 'setState',
4242
'getTotalRefunded',
4343
'hasForcedCanCreditmemo',
4444
'getIsInProcess',
@@ -76,13 +76,13 @@ public function testCheck(
7676
int $callCanSkipNum,
7777
string $currentState,
7878
string $expectedState = '',
79-
int $callSetStateNum = 0,
8079
bool $isInProcess = false,
8180
int $callGetIsInProcessNum = 0,
8281
bool $isCanceled = false,
8382
bool $canUnhold = false,
8483
bool $canInvoice = false
8584
) {
85+
$this->orderMock->setState($currentState);
8686
$this->orderMock->expects($this->any())
8787
->method('isCanceled')
8888
->willReturn($isCanceled);
@@ -98,50 +98,46 @@ public function testCheck(
9898
$this->orderMock->expects($this->exactly($callCanCreditmemoNum))
9999
->method('canCreditmemo')
100100
->willReturn($canCreditmemo);
101-
$this->orderMock->expects($this->once())
102-
->method('getState')
103-
->willReturn($currentState);
104101
$this->orderMock->expects($this->exactly($callGetIsInProcessNum))
105102
->method('getIsInProcess')
106103
->willReturn($isInProcess);
107-
$this->orderMock->expects($this->exactly($callSetStateNum))
108-
->method('setState')
109-
->with($expectedState)
110-
->will($this->returnSelf());
111104
$this->state->check($this->orderMock);
105+
$this->assertEquals($expectedState, $this->orderMock->getState());
112106
}
113107

114108
public function stateCheckDataProvider()
115109
{
116110
return [
117111
'processing - !canCreditmemo!canShip -> closed' =>
118-
[false, 1, false, 0, Order::STATE_PROCESSING, Order::STATE_CLOSED, 1],
112+
[false, 1, false, 0, Order::STATE_PROCESSING, Order::STATE_CLOSED],
119113
'complete - !canCreditmemo,!canShip -> closed' =>
120-
[false, 1, false, 0, Order::STATE_COMPLETE, Order::STATE_CLOSED, 1],
114+
[false, 1, false, 0, Order::STATE_COMPLETE, Order::STATE_CLOSED],
121115
'processing - !canCreditmemo,canShip -> closed' =>
122-
[false, 1, true, 0, Order::STATE_PROCESSING, Order::STATE_CLOSED, 1],
116+
[false, 1, true, 0, Order::STATE_PROCESSING, Order::STATE_CLOSED],
123117
'complete - !canCreditmemo,canShip -> closed' =>
124-
[false, 1, true, 0, Order::STATE_COMPLETE, Order::STATE_CLOSED, 1],
118+
[false, 1, true, 0, Order::STATE_COMPLETE, Order::STATE_CLOSED],
125119
'processing - canCreditmemo,!canShip -> complete' =>
126-
[true, 1, false, 1, Order::STATE_PROCESSING, Order::STATE_COMPLETE, 1],
120+
[true, 1, false, 1, Order::STATE_PROCESSING, Order::STATE_COMPLETE],
127121
'complete - canCreditmemo,!canShip -> complete' =>
128-
[true, 1, false, 0, Order::STATE_COMPLETE],
122+
[true, 1, false, 0, Order::STATE_COMPLETE, Order::STATE_COMPLETE],
129123
'processing - canCreditmemo, canShip -> processing' =>
130-
[true, 1, true, 1, Order::STATE_PROCESSING],
124+
[true, 1, true, 1, Order::STATE_PROCESSING, Order::STATE_PROCESSING],
131125
'complete - canCreditmemo, canShip -> complete' =>
132-
[true, 1, true, 0, Order::STATE_COMPLETE],
126+
[true, 1, true, 0, Order::STATE_COMPLETE, Order::STATE_COMPLETE],
133127
'new - canCreditmemo, canShip, IsInProcess -> processing' =>
134-
[true, 0, true, 0, Order::STATE_NEW, Order::STATE_PROCESSING, 1, true, 1],
128+
[true, 1, true, 1, Order::STATE_NEW, Order::STATE_PROCESSING, true, 1],
129+
'new - canCreditmemo, !canShip, IsInProcess -> processing' =>
130+
[true, 1, false, 1, Order::STATE_NEW, Order::STATE_COMPLETE, true, 1],
135131
'new - canCreditmemo, canShip, !IsInProcess -> new' =>
136-
[true, 0, true, 0, Order::STATE_NEW, '', 0, false, 1],
132+
[true, 0, true, 0, Order::STATE_NEW, Order::STATE_NEW, false, 1],
137133
'hold - canUnhold -> hold' =>
138-
[true, 0, true, 0, Order::STATE_HOLDED, '', 0, false, 0, false, true, false],
134+
[true, 0, true, 0, Order::STATE_HOLDED, Order::STATE_HOLDED, false, 0, false, true, false],
139135
'payment_review - canUnhold -> payment_review' =>
140-
[true, 0, true, 0, Order::STATE_PAYMENT_REVIEW, '', 0, false, 0, false, false, false],
136+
[true, 0, true, 0, Order::STATE_PAYMENT_REVIEW, Order::STATE_PAYMENT_REVIEW, false, 0, false, false, false],
141137
'pending_payment - canUnhold -> pending_payment' =>
142-
[true, 0, true, 0, Order::STATE_PENDING_PAYMENT, '', 0, false, 0, false, false, false],
138+
[true, 0, true, 0, Order::STATE_PENDING_PAYMENT, Order::STATE_PENDING_PAYMENT, false, 0, false, false, false],
143139
'cancelled - isCanceled -> cancelled' =>
144-
[true, 0, true, 0, Order::STATE_HOLDED, '', 0, false, 0, true, false, false],
140+
[true, 0, true, 0, Order::STATE_HOLDED, Order::STATE_HOLDED, false, 0, true, false, false],
145141
];
146142
}
147143
}

0 commit comments

Comments
 (0)