Skip to content

Commit 197f039

Browse files
committed
Merge remote-tracking branch 'trigger/MAGETWO-95429' into BugFixPR
2 parents 46e545d + 68085b3 commit 197f039

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ public function register()
277277
}
278278

279279
/**
280+
* Retrieves the collection used to track the shipment's items
281+
*
280282
* @return mixed
281283
*/
282284
public function getItemsCollection()
@@ -295,6 +297,8 @@ public function getItemsCollection()
295297
}
296298

297299
/**
300+
* Retrieves all non-deleted items from the shipment
301+
*
298302
* @return array
299303
*/
300304
public function getAllItems()
@@ -309,6 +313,8 @@ public function getAllItems()
309313
}
310314

311315
/**
316+
* Retrieves an item from the shipment using its ID
317+
*
312318
* @param string|int $itemId
313319
* @return bool|\Magento\Sales\Model\Order\Shipment\Item
314320
*/
@@ -323,6 +329,8 @@ public function getItemById($itemId)
323329
}
324330

325331
/**
332+
* Adds an item to the shipment
333+
*
326334
* @param \Magento\Sales\Model\Order\Shipment\Item $item
327335
* @return $this
328336
*/
@@ -353,6 +361,8 @@ public function getTracksCollection()
353361
}
354362

355363
/**
364+
* Retrieves all available tracks in the collection that aren't deleted
365+
*
356366
* @return array
357367
*/
358368
public function getAllTracks()
@@ -367,6 +377,8 @@ public function getAllTracks()
367377
}
368378

369379
/**
380+
* Retrieves a track using its ID
381+
*
370382
* @param string|int $trackId
371383
* @return bool|\Magento\Sales\Model\Order\Shipment\Track
372384
*/
@@ -381,6 +393,8 @@ public function getTrackById($trackId)
381393
}
382394

383395
/**
396+
* Addes a track to the collection and associates the shipment to the track
397+
*
384398
* @param \Magento\Sales\Model\Order\Shipment\Track $track
385399
* @return $this
386400
*/
@@ -409,8 +423,7 @@ public function addTrack(\Magento\Sales\Model\Order\Shipment\Track $track)
409423
}
410424

411425
/**
412-
* Adds comment to shipment with additional possibility to send it to customer via email
413-
* and show it in customer account
426+
* Adds comment to shipment with option to send it to customer via email and show it in customer account
414427
*
415428
* @param \Magento\Sales\Model\Order\Shipment\Comment|string $comment
416429
* @param bool $notify
@@ -574,13 +587,10 @@ public function setItems($items)
574587
public function getTracks()
575588
{
576589
if ($this->getData(ShipmentInterface::TRACKS) === null) {
577-
$collection = $this->_trackCollectionFactory->create()->setShipmentFilter($this->getId());
578-
if ($this->getId()) {
579-
foreach ($collection as $item) {
580-
$item->setShipment($this);
581-
}
582-
$this->setData(ShipmentInterface::TRACKS, $collection->getItems());
590+
foreach ($this->getTracksCollection() as $item) {
591+
$item->setShipment($this);
583592
}
593+
$this->setData(ShipmentInterface::TRACKS, $this->getTracksCollection()->getItems());
584594
}
585595
return $this->getData(ShipmentInterface::TRACKS);
586596
}

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ShipOrderTest extends \Magento\TestFramework\TestCase\WebapiAbstract
2525

2626
protected function setUp()
2727
{
28-
$this->markTestIncomplete('https://github.com/magento-engcom/msi/issues/1335');
2928
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
3029

3130
$this->shipmentRepository = $this->objectManager->get(
@@ -38,6 +37,7 @@ protected function setUp()
3837
*/
3938
public function testConfigurableShipOrder()
4039
{
40+
$this->markTestIncomplete('https://github.com/magento-engcom/msi/issues/1335');
4141
$productsQuantity = 1;
4242

4343
/** @var \Magento\Sales\Model\Order $existingOrder */
@@ -132,6 +132,39 @@ public function testShipOrder()
132132
);
133133
}
134134

135+
/**
136+
* Tests that not providing a tracking number produces the correct error. See MAGETWO-95429
137+
* @expectedException \Exception
138+
* @codingStandardsIgnoreStart
139+
* @expectedExceptionMessageRegExp /Shipment Document Validation Error\(s\):(?:\n|\\n)Please enter a tracking number./
140+
* @codingStandardsIgnoreEnd
141+
* @magentoApiDataFixture Magento/Sales/_files/order_new.php
142+
*/
143+
public function testShipOrderWithoutTrackingNumberReturnsError()
144+
{
145+
$this->_markTestAsRestOnly('SOAP requires an tracking number to be provided so this case is not possible.');
146+
147+
/** @var \Magento\Sales\Model\Order $existingOrder */
148+
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
149+
->loadByIncrementId('100000001');
150+
151+
$requestData = [
152+
'orderId' => $existingOrder->getId(),
153+
'comment' => [
154+
'comment' => 'Test Comment',
155+
'is_visible_on_front' => 1,
156+
],
157+
'tracks' => [
158+
[
159+
'title' => 'Simple shipment track',
160+
'carrier_code' => 'UPS'
161+
]
162+
]
163+
];
164+
165+
$this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);
166+
}
167+
135168
/**
136169
* @magentoApiDataFixture Magento/Bundle/_files/order_with_bundle_shipped_separately.php
137170
*/

0 commit comments

Comments
 (0)