Skip to content

Commit 814d849

Browse files
author
Aliaksei Yakimovich2
committed
MAGETWO-70885: [SOAP] The 'incrementId' property of the order with state 'complete' is increased after order status update
- Fixed an issue with increment id change when save order via webapi;
1 parent 6e534ad commit 814d849

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,11 @@ public function deleteById($id)
247247
/**
248248
* Perform persist operations for one entity
249249
*
250-
* @param \Magento\Sales\Api\Data\OrderInterface $entity
251-
* @return \Magento\Sales\Api\Data\OrderInterface
250+
* @param OrderInterface $entity
251+
* @return OrderInterface
252+
* @throws InputException
253+
* @throws NoSuchEntityException
254+
* @throws \Magento\Framework\Exception\AlreadyExistsException
252255
*/
253256
public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
254257
{
@@ -262,6 +265,18 @@ public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
262265
$entity->setShippingMethod($shipping->getMethod());
263266
}
264267
}
268+
269+
$entityId = $entity->getEntityId();
270+
if ($entityId && $entity->getIncrementId() == null) {
271+
try {
272+
$loadedEntity = $this->get($entityId);
273+
$entity->setIncrementId($loadedEntity->getIncrementId());
274+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
275+
} catch (NoSuchEntityException $e) {
276+
// non-existent entity
277+
}
278+
}
279+
265280
$this->metadata->getMapper()->save($entity);
266281
$this->registry[$entity->getEntityId()] = $entity;
267282
return $this->registry[$entity->getEntityId()];

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function testSave()
176176
$shippingMock->expects($this->once())->method('getAddress');
177177
$shippingMock->expects($this->once())->method('getMethod');
178178
$this->metadata->expects($this->once())->method('getMapper')->willReturn($mapperMock);
179+
$orderEntity->expects($this->once())->method('getIncrementId')->willReturn('0000000001');
179180
$mapperMock->expects($this->once())->method('save');
180181
$orderEntity->expects($this->any())->method('getEntityId')->willReturn(1);
181182
$this->orderRepository->save($orderEntity);

0 commit comments

Comments
 (0)