File tree 3 files changed +22
-4
lines changed
app/code/Magento/Sales/Model
ResourceModel/Order/Shipment
dev/tests/api-functional/testsuite/Magento/Sales/Service/V1 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 6
6
namespace Magento \Sales \Model \Order \Shipment ;
7
7
8
8
use Magento \Framework \Api \AttributeValueFactory ;
9
+ use Magento \Framework \Exception \LocalizedException ;
9
10
use Magento \Sales \Api \Data \ShipmentTrackInterface ;
10
11
use Magento \Sales \Model \AbstractModel ;
11
12
@@ -137,11 +138,16 @@ public function setShipment(\Magento\Sales\Model\Order\Shipment $shipment)
137
138
* Retrieve Shipment instance
138
139
*
139
140
* @return \Magento\Sales\Model\Order\Shipment
141
+ * @throws \Magento\Framework\Exception\LocalizedException
140
142
*/
141
143
public function getShipment ()
142
144
{
143
145
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
+ }
145
151
}
146
152
147
153
return $ this ->_shipment ;
Original file line number Diff line number Diff line change @@ -64,11 +64,13 @@ public function processRelation(\Magento\Framework\Model\AbstractModel $object)
64
64
}
65
65
if (null !== $ object ->getTracks ()) {
66
66
foreach ($ object ->getTracks () as $ track ) {
67
+ $ track ->setParentId ($ object ->getId ());
67
68
$ this ->shipmentTrackResource ->save ($ track );
68
69
}
69
70
}
70
71
if (null !== $ object ->getComments ()) {
71
72
foreach ($ object ->getComments () as $ comment ) {
73
+ $ comment ->setParentId ($ object ->getId ());
72
74
$ this ->shipmentCommentResource ->save ($ comment );
73
75
}
74
76
}
Original file line number Diff line number Diff line change @@ -79,11 +79,21 @@ public function testInvoke()
79
79
'increment_id ' => null ,
80
80
'created_at ' => null ,
81
81
'updated_at ' => null ,
82
- // 'packages' => null,
83
82
'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
+ ],
85
91
'items ' => $ items ,
86
- 'comments ' => [],
92
+ 'comments ' => [
93
+ [
94
+ 'comment ' => 'Shipment-related comment. '
95
+ ]
96
+ ],
87
97
];
88
98
$ result = $ this ->_webApiCall ($ serviceInfo , ['entity ' => $ data ]);
89
99
$ this ->assertNotEmpty ($ result );
You can’t perform that action at this time.
0 commit comments