File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -247,8 +247,11 @@ public function deleteById($id)
247
247
/**
248
248
* Perform persist operations for one entity
249
249
*
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
252
255
*/
253
256
public function save (\Magento \Sales \Api \Data \OrderInterface $ entity )
254
257
{
@@ -262,6 +265,18 @@ public function save(\Magento\Sales\Api\Data\OrderInterface $entity)
262
265
$ entity ->setShippingMethod ($ shipping ->getMethod ());
263
266
}
264
267
}
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
+
265
280
$ this ->metadata ->getMapper ()->save ($ entity );
266
281
$ this ->registry [$ entity ->getEntityId ()] = $ entity ;
267
282
return $ this ->registry [$ entity ->getEntityId ()];
Original file line number Diff line number Diff line change @@ -176,6 +176,7 @@ public function testSave()
176
176
$ shippingMock ->expects ($ this ->once ())->method ('getAddress ' );
177
177
$ shippingMock ->expects ($ this ->once ())->method ('getMethod ' );
178
178
$ this ->metadata ->expects ($ this ->once ())->method ('getMapper ' )->willReturn ($ mapperMock );
179
+ $ orderEntity ->expects ($ this ->once ())->method ('getIncrementId ' )->willReturn ('0000000001 ' );
179
180
$ mapperMock ->expects ($ this ->once ())->method ('save ' );
180
181
$ orderEntity ->expects ($ this ->any ())->method ('getEntityId ' )->willReturn (1 );
181
182
$ this ->orderRepository ->save ($ orderEntity );
You can’t perform that action at this time.
0 commit comments