1
1
<?php
2
2
/**
3
- *
4
- * Copyright © Magento, Inc. All rights reserved.
5
- * See COPYING.txt for license details.
3
+ * Copyright 2014 Adobe
4
+ * All Rights Reserved.
6
5
*/
7
6
namespace Magento \Shipping \Model \Shipping ;
8
7
9
8
use Magento \Framework \App \Filesystem \DirectoryList ;
10
9
use Magento \Framework \App \RequestInterface ;
10
+ use Magento \Sales \Model \Order \Shipment ;
11
11
12
12
/**
13
13
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14
+ * phpcs:disable Magento2.Functions.DiscouragedFunction
14
15
*/
15
16
class LabelGenerator
16
17
{
@@ -61,12 +62,14 @@ public function __construct(
61
62
}
62
63
63
64
/**
64
- * @param \Magento\Sales\Model\Order\Shipment $shipment
65
+ * Creates a shipping label
66
+ *
67
+ * @param Shipment $shipment
65
68
* @param RequestInterface $request
66
69
* @return void
67
70
* @throws \Magento\Framework\Exception\LocalizedException
68
71
*/
69
- public function create (\ Magento \ Sales \ Model \ Order \ Shipment $ shipment , RequestInterface $ request )
72
+ public function create (Shipment $ shipment , RequestInterface $ request )
70
73
{
71
74
$ order = $ shipment ->getOrder ();
72
75
$ carrier = $ this ->carrierFactory ->create ($ order ->getShippingMethod (true )->getCarrierCode ());
@@ -76,7 +79,8 @@ public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInt
76
79
$ shipment ->setPackages ($ request ->getParam ('packages ' ));
77
80
$ response = $ this ->labelFactory ->create ()->requestToShipment ($ shipment );
78
81
if ($ response ->hasErrors ()) {
79
- throw new \Magento \Framework \Exception \LocalizedException (__ ($ response ->getErrors ()));
82
+ $ firstError = $ response ->getErrors ()[0 ];
83
+ throw new \Magento \Framework \Exception \LocalizedException (__ ($ firstError ));
80
84
}
81
85
if (!$ response ->hasInfo ()) {
82
86
throw new \Magento \Framework \Exception \LocalizedException (__ ('Response info is not exist. ' ));
@@ -104,15 +108,17 @@ public function create(\Magento\Sales\Model\Order\Shipment $shipment, RequestInt
104
108
}
105
109
106
110
/**
107
- * @param \Magento\Sales\Model\Order\Shipment $shipment
111
+ * Adds tracking number to a shipment
112
+ *
113
+ * @param Shipment $shipment
108
114
* @param array $trackingNumbers
109
115
* @param string $carrierCode
110
116
* @param string $carrierTitle
111
117
*
112
118
* @return void
113
119
*/
114
120
private function addTrackingNumbersToShipment (
115
- \ Magento \ Sales \ Model \ Order \ Shipment $ shipment ,
121
+ Shipment $ shipment ,
116
122
$ trackingNumbers ,
117
123
$ carrierCode ,
118
124
$ carrierTitle
@@ -168,9 +174,11 @@ public function createPdfPageFromImageString($imageString)
168
174
$ directory = $ this ->filesystem ->getDirectoryWrite (
169
175
DirectoryList::TMP
170
176
);
171
- $ directory ->create ();
172
- $ image = @imagecreatefromstring ($ imageString );
173
- if (!$ image ) {
177
+
178
+ try {
179
+ $ directory ->create ();
180
+ $ image = imagecreatefromstring ($ imageString );
181
+ } catch (\Exception $ e ) {
174
182
return false ;
175
183
}
176
184
0 commit comments