File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -160,10 +160,21 @@ public function getCommentsList($id)
160
160
* @param int $id
161
161
* @param \Magento\Sales\Api\Data\OrderStatusHistoryInterface $statusHistory
162
162
* @return bool
163
+ * @throws \Magento\Framework\Exception\LocalizedException
163
164
*/
164
165
public function addComment ($ id , \Magento \Sales \Api \Data \OrderStatusHistoryInterface $ statusHistory )
165
166
{
166
167
$ order = $ this ->orderRepository ->get ($ id );
168
+
169
+ /**
170
+ * change order status is not allowed during add comment to the order
171
+ */
172
+ if ($ statusHistory ->getStatus () && $ statusHistory ->getStatus () != $ order ->getStatus ()) {
173
+ throw new \Magento \Framework \Exception \LocalizedException (
174
+ __ ('Unable to add comment: The status "%1" is not part of the order
175
+ status history. ' , $ statusHistory ->getStatus ())
176
+ );
177
+ }
167
178
$ order ->addStatusHistory ($ statusHistory );
168
179
$ this ->orderRepository ->save ($ order );
169
180
$ notify = $ statusHistory ['is_customer_notified ' ] ?? false ;
Original file line number Diff line number Diff line change 28
28
use PHPUnit \Framework \MockObject \MockObject ;
29
29
use PHPUnit \Framework \TestCase ;
30
30
use Psr \Log \LoggerInterface ;
31
+ use Magento \Framework \Phrase ;
32
+ use Magento \Framework \Exception \LocalizedException ;
31
33
32
34
/**
33
35
*
@@ -295,6 +297,22 @@ public function testAddComment()
295
297
$ this ->assertTrue ($ this ->orderService ->addComment (123 , $ this ->orderStatusHistoryMock ));
296
298
}
297
299
300
+ /**
301
+ * test for add comment with order status change case
302
+ */
303
+ public function testAddCommentWithStatus ()
304
+ {
305
+ $ params = ['status ' => 'holded ' ];
306
+ $ inputException = new LocalizedException (
307
+ new Phrase ('Unable to add comment: The status "%1" is not part of the order
308
+ status history. ' , $ params )
309
+ );
310
+ $ this ->orderStatusHistoryMock ->method ('getStatus ' )
311
+ ->willThrowException ($ inputException );
312
+ $ this ->expectException (LocalizedException::class);
313
+ $ this ->orderService ->addComment (123 , $ this ->orderStatusHistoryMock );
314
+ }
315
+
298
316
public function testNotify ()
299
317
{
300
318
$ this ->orderRepositoryMock ->expects ($ this ->once ())
You can’t perform that action at this time.
0 commit comments