Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 6e7c7f6

Browse files
author
Eric Bohanon
committed
MAGETWO-72747: [Magento Cloud] - /rest/default/V1/order/<order id>/ship and configurable products - for 2.2
1 parent 1010ae9 commit 6e7c7f6

File tree

5 files changed

+68
-155
lines changed

5 files changed

+68
-155
lines changed

app/code/Magento/Sales/Model/Order/Shipment/Item/Converter.php

Lines changed: 0 additions & 81 deletions
This file was deleted.

app/code/Magento/Sales/Model/Order/ShipmentDocumentFactory.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Sales\Api\Data\OrderInterface;
1515
use Magento\Sales\Api\Data\ShipmentCommentCreationInterface;
1616
use Magento\Sales\Api\Data\ShipmentCreationArgumentsInterface;
17-
use Magento\Sales\Model\Order\Shipment\Item\Converter;
17+
use Magento\Sales\Api\Data\OrderItemInterface;
1818

1919
/**
2020
* Class ShipmentDocumentFactory
@@ -39,11 +39,6 @@ class ShipmentDocumentFactory
3939
*/
4040
private $hydratorPool;
4141

42-
/**
43-
* @var Converter
44-
*/
45-
private $converter;
46-
4742
/**
4843
* ShipmentDocumentFactory constructor.
4944
*
@@ -55,14 +50,11 @@ class ShipmentDocumentFactory
5550
public function __construct(
5651
ShipmentFactory $shipmentFactory,
5752
HydratorPool $hydratorPool,
58-
TrackFactory $trackFactory,
59-
Converter $converter = null
53+
TrackFactory $trackFactory
6054
) {
6155
$this->shipmentFactory = $shipmentFactory;
6256
$this->trackFactory = $trackFactory;
6357
$this->hydratorPool = $hydratorPool;
64-
$this->converter = $converter
65-
?: \Magento\Framework\App\ObjectManager::getInstance()->get(Converter::class);
6658
}
6759

6860
/**
@@ -87,13 +79,34 @@ public function create(
8779
array $packages = [],
8880
ShipmentCreationArgumentsInterface $arguments = null
8981
) {
90-
$shipmentItems = $this->converter->convertToQuantityArray($items, $order);
82+
$shipmentItems = [];
83+
if (empty($items)) {
84+
/** @var OrderItemInterface $item */
85+
foreach ($order->getItems() as $item) {
86+
if (!$item->getIsVirtual() && !$item->getParentItem()) {
87+
$shipmentItems[$item->getItemId()] = $item->getQtyOrdered();
88+
}
89+
}
90+
} else {
91+
/** @var ShipmentItemCreationInterface $item */
92+
foreach ($items as $item) {
93+
$shipmentItems[$item->getOrderItemId()] = $item->getQty();
94+
}
95+
}
96+
9197
/** @var Shipment $shipment */
9298
$shipment = $this->shipmentFactory->create(
9399
$order,
94100
$shipmentItems
95101
);
96-
$this->prepareTracks($shipment, $tracks);
102+
103+
foreach ($tracks as $track) {
104+
$hydrator = $this->hydratorPool->getHydrator(
105+
\Magento\Sales\Api\Data\ShipmentTrackCreationInterface::class
106+
);
107+
$shipment->addTrack($this->trackFactory->create(['data' => $hydrator->extract($track)]));
108+
}
109+
97110
if ($comment) {
98111
$shipment->addComment(
99112
$comment->getComment(),
@@ -104,22 +117,4 @@ public function create(
104117

105118
return $shipment;
106119
}
107-
108-
/**
109-
* Adds tracks to the shipment.
110-
*
111-
* @param ShipmentInterface $shipment
112-
* @param ShipmentTrackCreationInterface[] $tracks
113-
* @return ShipmentInterface
114-
*/
115-
private function prepareTracks(\Magento\Sales\Api\Data\ShipmentInterface $shipment, array $tracks)
116-
{
117-
foreach ($tracks as $track) {
118-
$hydrator = $this->hydratorPool->getHydrator(
119-
\Magento\Sales\Api\Data\ShipmentTrackCreationInterface::class
120-
);
121-
$shipment->addTrack($this->trackFactory->create(['data' => $hydrator->extract($track)]));
122-
}
123-
return $shipment;
124-
}
125120
}

app/code/Magento/Sales/Test/Unit/Model/Order/ShipmentDocumentFactoryTest.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Magento\Sales\Model\Order\Shipment\TrackFactory;
1717
use Magento\Sales\Model\Order\Shipment\Track;
1818
use Magento\Framework\EntityManager\HydratorInterface;
19-
use Magento\Sales\Model\Order\Shipment\Item\Converter;
2019

2120
/**
2221
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -73,11 +72,6 @@ class ShipmentDocumentFactoryTest extends \PHPUnit\Framework\TestCase
7372
*/
7473
private $trackMock;
7574

76-
/**
77-
* @var Converter | \PHPUnit_Framework_MockObject_MockObject
78-
*/
79-
private $converterMock;
80-
8175
protected function setUp()
8276
{
8377
$this->shipmentFactoryMock = $this->getMockBuilder(ShipmentFactory::class)
@@ -118,15 +112,10 @@ protected function setUp()
118112
->disableOriginalConstructor()
119113
->getMockForAbstractClass();
120114

121-
$this->converterMock = $this->getMockBuilder(Converter::class)
122-
->disableOriginalConstructor()
123-
->getMock();
124-
125115
$this->shipmentDocumentFactory = new ShipmentDocumentFactory(
126116
$this->shipmentFactoryMock,
127117
$this->hydratorPoolMock,
128-
$this->trackFactoryMock,
129-
$this->converterMock
118+
$this->trackFactoryMock
130119
);
131120
}
132121

@@ -139,6 +128,8 @@ public function testCreate()
139128
$packages = [];
140129
$items = [1 => 10];
141130

131+
$this->itemMock->expects($this->once())->method('getOrderItemId')->willReturn(1);
132+
$this->itemMock->expects($this->once())->method('getQty')->willReturn(10);
142133
$this->shipmentFactoryMock->expects($this->once())
143134
->method('create')
144135
->with(
@@ -166,11 +157,6 @@ public function testCreate()
166157
->with(['data' => $trackData])
167158
->willReturn($this->trackMock);
168159

169-
$this->converterMock->expects($this->once())
170-
->method('convertToQuantityArray')
171-
->with([$this->itemMock], $this->orderMock)
172-
->willReturn($items);
173-
174160
if ($appendComment) {
175161
$comment = "New comment!";
176162
$visibleOnFront = true;

app/code/Magento/Shipping/Controller/Adminhtml/Order/ShipmentLoader.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
use Magento\Framework\Registry;
1212
use Magento\Sales\Api\Data\ShipmentTrackCreationInterface;
1313
use Magento\Sales\Api\Data\ShipmentTrackCreationInterfaceFactory;
14+
use Magento\Sales\Api\Data\ShipmentItemCreationInterfaceFactory;
1415
use Magento\Sales\Api\ShipmentRepositoryInterface;
1516
use Magento\Sales\Api\OrderRepositoryInterface;
16-
use Magento\Sales\Model\Order\Shipment\Item\Converter;
1717
use Magento\Sales\Model\Order\ShipmentDocumentFactory;
18+
use Magento\Sales\Api\Data\ShipmentItemCreationInterface;
1819

1920
/**
2021
* Class ShipmentLoader
@@ -51,11 +52,6 @@ class ShipmentLoader extends DataObject
5152
*/
5253
private $orderRepository;
5354

54-
/**
55-
* @var Converter
56-
*/
57-
private $converter;
58-
5955
/**
6056
* @var ShipmentDocumentFactory
6157
*/
@@ -66,33 +62,38 @@ class ShipmentLoader extends DataObject
6662
*/
6763
private $trackFactory;
6864

65+
/**
66+
* @var ShipmentItemCreationInterfaceFactory
67+
*/
68+
private $itemFactory;
69+
6970
/**
7071
* @param ManagerInterface $messageManager
7172
* @param Registry $registry
7273
* @param ShipmentRepositoryInterface $shipmentRepository
7374
* @param OrderRepositoryInterface $orderRepository
74-
* @param Converter $converter
7575
* @param ShipmentDocumentFactory $documentFactory
7676
* @param ShipmentTrackCreationInterfaceFactory $trackFactory
77+
* @param ShipmentItemCreationInterfaceFactory $itemFactory
7778
* @param array $data
7879
*/
7980
public function __construct(
8081
ManagerInterface $messageManager,
8182
Registry $registry,
8283
ShipmentRepositoryInterface $shipmentRepository,
8384
OrderRepositoryInterface $orderRepository,
84-
Converter $converter,
8585
ShipmentDocumentFactory $documentFactory,
8686
ShipmentTrackCreationInterfaceFactory $trackFactory,
87+
ShipmentItemCreationInterfaceFactory $itemFactory,
8788
array $data = []
8889
) {
8990
$this->messageManager = $messageManager;
9091
$this->registry = $registry;
9192
$this->shipmentRepository = $shipmentRepository;
9293
$this->orderRepository = $orderRepository;
93-
$this->converter = $converter;
9494
$this->documentFactory = $documentFactory;
9595
$this->trackFactory = $trackFactory;
96+
$this->itemFactory = $itemFactory;
9697
parent::__construct($data);
9798
}
9899

@@ -134,9 +135,18 @@ public function load()
134135
return false;
135136
}
136137

138+
$shipmentItems = [];
139+
foreach ($this->getItemQtys() as $itemId => $quantity) {
140+
/** @var ShipmentItemCreationInterface $item */
141+
$item = $this->itemFactory->create();
142+
$item->setOrderItemId($itemId);
143+
$item->setQty($quantity);
144+
$shipmentItems[] = $item;
145+
}
146+
137147
$shipment = $this->documentFactory->create(
138148
$order,
139-
$this->converter->convertToItemCreationArray($this->getItemQtys()),
149+
$shipmentItems,
140150
$this->getTrackingArray()
141151
);
142152
}
@@ -180,6 +190,7 @@ private function getTrackingArray()
180190
$trackCreation->setCarrierCode($track['carrier_code']);
181191
$trackingCreation[] = $trackCreation;
182192
}
193+
183194
return $trackingCreation;
184195
}
185196
}

0 commit comments

Comments
 (0)