Skip to content

Commit 6a4e778

Browse files
committed
Merge branch 'MC-37539' of https://github.com/magento-mpi/magento2ce into PR-09-24-2020
2 parents ce2563e + 086942e commit 6a4e778

File tree

3 files changed

+51
-12
lines changed

3 files changed

+51
-12
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ public function execute(
177177
$connection->beginTransaction();
178178
try {
179179
$this->orderRegistrar->register($order, $shipment);
180-
$order->setState(
181-
$this->orderStateResolver->getStateForOrder($order, [OrderStateResolverInterface::IN_PROGRESS])
182-
);
183-
$order->setStatus($this->config->getStateDefaultStatus($order->getState()));
184-
$shippingData = $this->shipmentRepository->save($shipment);
180+
$shipment = $this->shipmentRepository->save($shipment);
181+
if ($order->getState() === Order::STATE_NEW) {
182+
$order->setState(
183+
$this->orderStateResolver->getStateForOrder($order, [OrderStateResolverInterface::IN_PROGRESS])
184+
);
185+
$order->setStatus($this->config->getStateDefaultStatus($order->getState()));
186+
}
185187
$this->orderRepository->save($order);
186188
$connection->commit();
187189
} catch (\Exception $e) {
@@ -191,9 +193,7 @@ public function execute(
191193
__('Could not save a shipment, see error log for details')
192194
);
193195
}
194-
if ($shipment && empty($shipment->getEntityId())) {
195-
$shipment->setEntityId($shippingData->getEntityId());
196-
}
196+
197197
if ($notify) {
198198
if (!$appendComment) {
199199
$comment = null;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ public function testExecute($orderId, $items, $notify, $appendComment)
270270
->method('setState')
271271
->with(Order::STATE_PROCESSING)
272272
->willReturnSelf();
273-
$this->orderMock->expects($this->once())
273+
$this->orderMock->expects($this->exactly(2))
274274
->method('getState')
275-
->willReturn(Order::STATE_PROCESSING);
275+
->willReturn(Order::STATE_NEW);
276276
$this->configMock->expects($this->once())
277277
->method('getStateDefaultStatus')
278-
->with(Order::STATE_PROCESSING)
278+
->with(Order::STATE_NEW)
279279
->willReturn('Processing');
280280
$this->orderMock->expects($this->once())
281281
->method('setStatus')
@@ -294,7 +294,7 @@ public function testExecute($orderId, $items, $notify, $appendComment)
294294
->method('notify')
295295
->with($this->orderMock, $this->shipmentMock, $this->shipmentCommentCreationMock);
296296
}
297-
$this->shipmentMock->expects($this->exactly(2))
297+
$this->shipmentMock->expects($this->exactly(1))
298298
->method('getEntityId')
299299
->willReturn(2);
300300
$this->assertEquals(

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function testConfigurableShipOrder()
6262
$shipmentId = (int)$this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);
6363
$this->assertNotEmpty($shipmentId);
6464

65+
$shipment = null;
6566
try {
6667
$shipment = $this->shipmentRepository->get($shipmentId);
6768
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
@@ -89,6 +90,42 @@ public function testConfigurableShipOrder()
8990
);
9091
}
9192

93+
/**
94+
* Tests that order doesn't change a status from custom to the default after shipment creation.
95+
*
96+
* @magentoApiDataFixture Magento/Sales/_files/order_status.php
97+
*/
98+
public function testShipOrderStatusPreserve()
99+
{
100+
$incrementId = '100000001';
101+
$orderStatus = 'example';
102+
103+
/** @var Order $existingOrder */
104+
$order = $this->getOrder($incrementId);
105+
$this->assertEquals($orderStatus, $order->getStatus());
106+
107+
$requestData = [
108+
'orderId' => $order->getId()
109+
];
110+
/** @var OrderItemInterface $item */
111+
foreach ($order->getAllItems() as $item) {
112+
$requestData['items'][] = [
113+
'order_item_id' => $item->getItemId(),
114+
'qty' => $item->getQtyOrdered(),
115+
];
116+
}
117+
118+
$shipmentId = $this->_webApiCall($this->getServiceInfo($order), $requestData);
119+
$this->assertNotEmpty($shipmentId);
120+
$actualOrder = $this->getOrder($order->getIncrementId());
121+
122+
$this->assertEquals(
123+
$order->getStatus(),
124+
$actualOrder->getStatus(),
125+
'Failed asserting that Order status wasn\'t changed'
126+
);
127+
}
128+
92129
/**
93130
* @magentoApiDataFixture Magento/Sales/_files/order_new.php
94131
*/
@@ -214,6 +251,7 @@ public function testPartialShipOrderWithBundleShippedSeparately()
214251
$shipmentId = $this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);
215252
$this->assertNotEmpty($shipmentId);
216253

254+
$shipment = null;
217255
try {
218256
$shipment = $this->shipmentRepository->get($shipmentId);
219257
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
@@ -268,6 +306,7 @@ public function testPartialShipOrderWithTwoBundleShippedSeparatelyContainsSameSi
268306
$shipmentId = $this->_webApiCall($this->getServiceInfo($order), $requestData);
269307
$this->assertNotEmpty($shipmentId);
270308

309+
$shipment = null;
271310
try {
272311
$shipment = $this->shipmentRepository->get($shipmentId);
273312
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {

0 commit comments

Comments
 (0)