Skip to content

Commit aded675

Browse files
author
Cari Spruiell
committed
MAGETWO-50202: [GitHub] Couldn't save shipment data #527
- restore fixes to branch and fix test
1 parent 17a571b commit aded675

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public function testInvoke()
7979
'increment_id' => null,
8080
'created_at' => null,
8181
'updated_at' => null,
82-
// 'packages' => null,
8382
'shipping_label' => null,
8483
'tracks' => [
8584
[
@@ -98,7 +97,10 @@ public function testInvoke()
9897
'items' => $items,
9998
'comments' => [
10099
[
101-
'comment' => 'Shipment-related comment.'
100+
'comment' => 'Shipment-related comment.',
101+
'is_customer_notified' => null,
102+
'is_visible_on_front' => null,
103+
'parent_id' => null
102104
]
103105
],
104106
];

0 commit comments

Comments
 (0)