Skip to content

Commit 514d2a3

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3178' into Tier4-Kings-PR-08-23-2024
2 parents f473ebf + 18dee3d commit 514d2a3

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/AddComment.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Sales\Controller\Adminhtml\Order;
77

88
use Magento\Framework\App\Action\HttpPostActionInterface;
9-
use Magento\Sales\Model\Order;
9+
use Magento\Sales\Api\Data\OrderInterface;
1010
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
1111

1212
/**
@@ -45,7 +45,7 @@ public function execute()
4545
throw new \Magento\Framework\Exception\LocalizedException(__($error));
4646
}
4747

48-
$orderStatus = $this->getOrderStatus($order->getDataByKey('status'), $data['status']);
48+
$orderStatus = $this->getOrderStatus($order, $data['status']);
4949
$order->setStatus($orderStatus);
5050
$notify = $data['is_customer_notified'] ?? false;
5151
$visible = $data['is_visible_on_front'] ?? false;
@@ -85,13 +85,21 @@ public function execute()
8585
/**
8686
* Get order status to set
8787
*
88-
* @param string $orderStatus
88+
* @param OrderInterface $order
8989
* @param string $historyStatus
9090
* @return string
9191
*/
92-
private function getOrderStatus(string $orderStatus, string $historyStatus): string
92+
private function getOrderStatus(OrderInterface $order, string $historyStatus): string
9393
{
94-
return ($orderStatus === Order::STATE_PROCESSING || $orderStatus === Order::STATUS_FRAUD) ? $historyStatus
95-
: $orderStatus;
94+
$config = $order->getConfig();
95+
if ($config === null) {
96+
return $historyStatus;
97+
}
98+
$statuses = $config->getStateStatuses($order->getState());
99+
100+
if (!isset($statuses[$historyStatus])) {
101+
return $order->getDataByKey('status');
102+
}
103+
return $historyStatus;
96104
}
97105
}

app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/AddCommentTest.php

+28-14
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,20 @@ protected function setUp(): void
127127
* @param string $orderStatus
128128
* @param bool $userHasResource
129129
* @param bool $expectedNotify
130+
* @param string $expectedOrderStatus
130131
*
131132
* @dataProvider executeWillNotifyCustomerDataProvider
132133
*/
133134
public function testExecuteWillNotifyCustomer(
134135
array $historyData,
135136
string $orderStatus,
136137
bool $userHasResource,
137-
bool $expectedNotify
138+
bool $expectedNotify,
139+
string $expectedOrderStatus
138140
) {
139141
$orderId = 30;
140142
$this->requestMock->expects($this->once())->method('getParam')->with('order_id')->willReturn($orderId);
141-
$this->orderMock->expects($this->atLeastOnce())->method('getDataByKey')
143+
$this->orderMock->expects($this->any())->method('getDataByKey')
142144
->with('status')->willReturn($orderStatus);
143145
$this->orderRepositoryMock->expects($this->once())
144146
->method('get')
@@ -152,6 +154,12 @@ public function testExecuteWillNotifyCustomer(
152154
$this->objectManagerMock->expects($this->once())->method('create')->willReturn(
153155
$this->createMock(OrderCommentSender::class)
154156
);
157+
158+
// Verify the getOrderStatus method call
159+
$this->orderMock->expects($this->once())->method('setStatus')->with($expectedOrderStatus);
160+
$this->orderMock->expects($this->once())->method('save');
161+
$this->statusHistoryCommentMock->expects($this->once())->method('save');
162+
155163
$this->addCommentController->execute();
156164
}
157165

@@ -167,57 +175,63 @@ public function executeWillNotifyCustomerDataProvider()
167175
'is_customer_notified' => true,
168176
'status' => 'processing'
169177
],
170-
'orderStatus' =>'processing',
178+
'orderStatus' => 'processing',
171179
'userHasResource' => true,
172-
'expectedNotify' => true
180+
'expectedNotify' => true,
181+
'expectedOrderStatus' => 'processing'
173182
],
174183
'User Has Access - Notify False' => [
175184
'postData' => [
176185
'comment' => 'Great Product!',
177186
'is_customer_notified' => false,
178187
'status' => 'processing'
179188
],
180-
'orderStatus' =>'processing',
189+
'orderStatus' => 'processing',
181190
'userHasResource' => true,
182-
'expectedNotify' => false
191+
'expectedNotify' => false,
192+
'expectedOrderStatus' => 'processing'
183193
],
184194
'User Has Access - Notify Unset' => [
185195
'postData' => [
186196
'comment' => 'Great Product!',
187197
'status' => 'processing'
188198
],
189-
'orderStatus' =>'fraud',
199+
'orderStatus' => 'fraud',
190200
'userHasResource' => true,
191-
'expectedNotify' => false
201+
'expectedNotify' => false,
202+
'expectedOrderStatus' => 'processing'
192203
],
193204
'User No Access - Notify True' => [
194205
'postData' => [
195206
'comment' => 'Great Product!',
196207
'is_customer_notified' => true,
197208
'status' => 'fraud'
198209
],
199-
'orderStatus' =>'processing',
210+
'orderStatus' => 'processing',
200211
'userHasResource' => false,
201-
'expectedNotify' => false
212+
'expectedNotify' => false,
213+
'expectedOrderStatus' => 'fraud'
202214
],
203215
'User No Access - Notify False' => [
204216
'postData' => [
205217
'comment' => 'Great Product!',
206218
'is_customer_notified' => false,
207219
'status' => 'processing'
208220
],
209-
'orderStatus' =>'complete',
221+
'orderStatus' => 'complete',
210222
'userHasResource' => false,
211-
'expectedNotify' => false
223+
'expectedNotify' => false,
224+
'expectedOrderStatus' => 'processing'
212225
],
213226
'User No Access - Notify Unset' => [
214227
'postData' => [
215228
'comment' => 'Great Product!',
216229
'status' => 'processing'
217230
],
218-
'orderStatus' =>'complete',
231+
'orderStatus' => 'complete',
219232
'userHasResource' => false,
220-
'expectedNotify' => false
233+
'expectedNotify' => false,
234+
'expectedOrderStatus' => 'processing'
221235
],
222236
];
223237
}

0 commit comments

Comments
 (0)