Skip to content

Commit 154c61c

Browse files
author
Alexander Paliarush
committed
MAGETWO-50202: [GitHub] Couldn't save shipment data #527
1 parent 798a842 commit 154c61c

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 7 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;

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
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,21 @@ 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+
'track_number' => '12345678'
89+
]
90+
],
8591
'items' => $items,
86-
'comments' => [],
92+
'comments' => [
93+
[
94+
'comment' => 'Shipment-related comment.'
95+
]
96+
],
8797
];
8898
$result = $this->_webApiCall($serviceInfo, ['entity' => $data]);
8999
$this->assertNotEmpty($result);

0 commit comments

Comments
 (0)