File tree Expand file tree Collapse file tree 5 files changed +17
-5
lines changed
ResourceModel/Order/Shipment
Test/Unit/Model/ResourceModel/Order/Shipment
Shipping/Test/Unit/Model/Order
dev/tests/api-functional/testsuite/Magento/Sales/Service/V1 Expand file tree Collapse file tree 5 files changed +17
-5
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 ;
@@ -208,6 +214,7 @@ public function addData(array $data)
208
214
}
209
215
210
216
//@codeCoverageIgnoreStart
217
+
211
218
/**
212
219
* Returns track_number
213
220
*
@@ -408,5 +415,6 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentTrackExte
408
415
{
409
416
return $ this ->_setExtensionAttributes ($ extensionAttributes );
410
417
}
418
+
411
419
//@codeCoverageIgnoreEnd
412
420
}
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 @@ -111,7 +111,7 @@ protected function setUp()
111
111
112
112
public function testProcessRelations ()
113
113
{
114
- $ this ->shipmentMock ->expects ($ this ->once ( ))
114
+ $ this ->shipmentMock ->expects ($ this ->exactly ( 3 ))
115
115
->method ('getId ' )
116
116
->willReturn ('shipment-id-value ' );
117
117
$ this ->shipmentMock ->expects ($ this ->exactly (2 ))
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ public function testLookup()
52
52
'Magento\Shipping\Model\Order\Track ' ,
53
53
['carrierFactory ' => $ carrierFactory , 'shipmentRepository ' => $ shipmentRepository ]
54
54
);
55
-
55
+ $ model -> setParentId ( 1 );
56
56
$ this ->assertEquals ('trackingInfo ' , $ model ->getNumberDetail ());
57
57
}
58
58
}
Original file line number Diff line number Diff line change @@ -79,7 +79,6 @@ 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
83
'tracks ' => [
85
84
[
@@ -98,7 +97,10 @@ public function testInvoke()
98
97
'items ' => $ items ,
99
98
'comments ' => [
100
99
[
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
102
104
]
103
105
],
104
106
];
You can’t perform that action at this time.
0 commit comments