Skip to content

Commit 61138dd

Browse files
author
Aliaksei Yakimovich2
committed
MAGETWO-70885: [SOAP] The 'incrementId' property of the order with state 'complete' is increased after order status update
- Modified implementation without additional model loading; - Fixed tests;
1 parent ee9b46d commit 61138dd

File tree

5 files changed

+53
-19
lines changed

5 files changed

+53
-19
lines changed

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,6 @@ public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
266266
}
267267
}
268268

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-
280269
$this->metadata->getMapper()->save($entity);
281270
$this->registry[$entity->getEntityId()] = $entity;
282271
return $this->registry[$entity->getEntityId()];

app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/**
1515
* Abstract sales entity provides to its children knowledge about eventPrefix and eventObject
1616
*
17+
* phpcs:disable Magento2.Classes.AbstractApi
1718
* @api
1819
* @SuppressWarnings(PHPMD.NumberOfChildren)
1920
* @since 100.0.2
@@ -96,6 +97,7 @@ public function saveAttribute(\Magento\Framework\Model\AbstractModel $object, $a
9697

9798
/**
9899
* Prepares data for saving and removes update time (if exists).
100+
*
99101
* This prevents saving same update time on each entity update.
100102
*
101103
* @param \Magento\Framework\Model\AbstractModel $object
@@ -114,6 +116,7 @@ protected function _prepareDataForSave(\Magento\Framework\Model\AbstractModel $o
114116

115117
/**
116118
* Perform actions before object save
119+
*
117120
* Perform actions before object save, calculate next sequence value for increment Id
118121
*
119122
* @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
@@ -122,7 +125,7 @@ protected function _prepareDataForSave(\Magento\Framework\Model\AbstractModel $o
122125
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
123126
{
124127
/** @var \Magento\Sales\Model\AbstractModel $object */
125-
if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
128+
if ($object instanceof EntityInterface && $object->getEntityId() == null) {
126129
$store = $object->getStore();
127130
$storeId = $store->getId();
128131
if ($storeId === null) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ 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');
180179
$mapperMock->expects($this->once())->method('save');
181180
$orderEntity->expects($this->any())->method('getEntityId')->willReturn(1);
182181
$this->orderRepository->save($orderEntity);

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/OrderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function testSave()
198198
->with('10000001')
199199
->willReturnSelf();
200200
$this->orderMock->expects($this->once())
201-
->method('getIncrementId')
201+
->method('getEntityId')
202202
->willReturn(null);
203203
$this->orderMock->expects($this->once())
204204
->method('getData')

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ public function testOrderUpdate()
4545
$order = $this->objectManager->get(\Magento\Sales\Model\Order::class)
4646
->loadByIncrementId(self::ORDER_INCREMENT_ID);
4747

48-
$entityData = [
49-
OrderInterface::ENTITY_ID => $order->getId(),
50-
OrderInterface::STATE => 'processing',
51-
OrderInterface::STATUS => 'processing'
52-
];
48+
$entityData = $this->getOrderData($order);
49+
5350
$requestData = ['entity' => $entityData];
5451

5552
$serviceInfo = [
@@ -73,4 +70,50 @@ public function testOrderUpdate()
7370
$actualOrder->getData(OrderInterface::INCREMENT_ID)
7471
);
7572
}
73+
74+
/**
75+
* Prepare order data for request
76+
*
77+
* @param \Magento\Sales\Model\Order $order
78+
* @return array
79+
*/
80+
private function getOrderData(\Magento\Sales\Model\Order $order)
81+
{
82+
if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) {
83+
$entityData = $order->getData();
84+
unset($entityData[OrderInterface::INCREMENT_ID]);
85+
$entityData[OrderInterface::STATE] = 'processing';
86+
$entityData[OrderInterface::STATUS] = 'processing';
87+
88+
$orderData = $order->getData();
89+
$orderData['billing_address'] = $order->getBillingAddress()->getData();
90+
$orderData['billing_address']['street'] = ['Street'];
91+
92+
$orderItems = [];
93+
foreach ($order->getItems() as $item) {
94+
$orderItems[] = $item->getData();
95+
}
96+
$orderData['items'] = $orderItems;
97+
98+
$shippingAddress = $order->getShippingAddress()->getData();
99+
$orderData['extension_attributes']['shipping_assignments'] =
100+
[
101+
[
102+
'shipping' => [
103+
'address' => $shippingAddress,
104+
'method' => 'flatrate_flatrate'
105+
],
106+
'items' => $order->getItems(),
107+
'stock_id' => null,
108+
]
109+
];
110+
} else {
111+
$orderData = [
112+
OrderInterface::ENTITY_ID => $order->getId(),
113+
OrderInterface::STATE => 'processing',
114+
OrderInterface::STATUS => 'processing'
115+
];
116+
}
117+
return $orderData;
118+
}
76119
}

0 commit comments

Comments
 (0)