Skip to content

Commit 30d1f56

Browse files
author
Cari Spruiell
committed
Merge branch 'MAGETWO-50202-New-Shipment' into bug-fixes
2 parents f92932b + 2a31a28 commit 30d1f56

File tree

6 files changed

+38
-6
lines changed

6 files changed

+38
-6
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Sales\Model\Order\Shipment;
77

88
use Magento\Framework\Api\AttributeValueFactory;
9+
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Sales\Api\Data\ShipmentTrackInterface;
1011
use Magento\Sales\Model\AbstractModel;
1112

@@ -137,11 +138,16 @@ public function setShipment(\Magento\Sales\Model\Order\Shipment $shipment)
137138
* Retrieve Shipment instance
138139
*
139140
* @return \Magento\Sales\Model\Order\Shipment
141+
* @throws \Magento\Framework\Exception\LocalizedException
140142
*/
141143
public function getShipment()
142144
{
143145
if (!$this->_shipment instanceof \Magento\Sales\Model\Order\Shipment) {
144-
$this->_shipment = $this->shipmentRepository->get($this->getParentId());
146+
if ($this->getParentId()) {
147+
$this->_shipment = $this->shipmentRepository->get($this->getParentId());
148+
} else {
149+
throw new LocalizedException(__("Parent shipment cannot be loaded for track object."));
150+
}
145151
}
146152

147153
return $this->_shipment;
@@ -208,6 +214,7 @@ public function addData(array $data)
208214
}
209215

210216
//@codeCoverageIgnoreStart
217+
211218
/**
212219
* Returns track_number
213220
*
@@ -408,5 +415,6 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentTrackExte
408415
{
409416
return $this->_setExtensionAttributes($extensionAttributes);
410417
}
418+
411419
//@codeCoverageIgnoreEnd
412420
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ public function processRelation(\Magento\Framework\Model\AbstractModel $object)
6464
}
6565
if (null !== $object->getTracks()) {
6666
foreach ($object->getTracks() as $track) {
67+
$track->setParentId($object->getId());
6768
$this->shipmentTrackResource->save($track);
6869
}
6970
}
7071
if (null !== $object->getComments()) {
7172
foreach ($object->getComments() as $comment) {
73+
$comment->setParentId($object->getId());
7274
$this->shipmentCommentResource->save($comment);
7375
}
7476
}

app/code/Magento/Sales/Test/Unit/Model/ResourceModel/Order/Shipment/RelationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function setUp()
111111

112112
public function testProcessRelations()
113113
{
114-
$this->shipmentMock->expects($this->once())
114+
$this->shipmentMock->expects($this->exactly(3))
115115
->method('getId')
116116
->willReturn('shipment-id-value');
117117
$this->shipmentMock->expects($this->exactly(2))

app/code/Magento/Shipping/Test/Unit/Model/Order/TrackTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testLookup()
5252
'Magento\Shipping\Model\Order\Track',
5353
['carrierFactory' => $carrierFactory, 'shipmentRepository' => $shipmentRepository]
5454
);
55-
55+
$model->setParentId(1);
5656
$this->assertEquals('trackingInfo', $model->getNumberDetail());
5757
}
5858
}

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,30 @@ public function testInvoke()
7979
'increment_id' => null,
8080
'created_at' => null,
8181
'updated_at' => null,
82-
// 'packages' => null,
8382
'shipping_label' => null,
84-
'tracks' => [],
83+
'tracks' => [
84+
[
85+
'carrier_code' => 'UPS',
86+
'order_id' => $order->getId(),
87+
'title' => 'ground',
88+
'description' => null,
89+
'track_number' => '12345678',
90+
'parent_id' => null,
91+
'created_at' => null,
92+
'updated_at' => null,
93+
'qty' => null,
94+
'weight' => null
95+
]
96+
],
8597
'items' => $items,
86-
'comments' => [],
98+
'comments' => [
99+
[
100+
'comment' => 'Shipment-related comment.',
101+
'is_customer_notified' => null,
102+
'is_visible_on_front' => null,
103+
'parent_id' => null
104+
]
105+
],
87106
];
88107
$result = $this->_webApiCall($serviceInfo, ['entity' => $data]);
89108
$this->assertNotEmpty($result);

dev/tests/integration/testsuite/Magento/Shipping/Helper/DataTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function testGetTrackingPopupUrlBySalesModel($modelName, $getIdMethod, $e
4545
if ('Magento\Sales\Model\Order' == $modelName) {
4646
$model->setProtectCode($code);
4747
}
48+
if ('Magento\Sales\Model\Order\Shipment\Track' == $modelName) {
49+
$model->setParentId(1);
50+
}
4851

4952
$actual = $this->_helper->getTrackingPopupUrlBySalesModel($model);
5053
$this->assertEquals($expected, $actual);

0 commit comments

Comments
 (0)