8
8
9
9
use Magento \Sales \Model \Order \Email \Sender \ShipmentSender ;
10
10
use Magento \Backend \App \Action ;
11
+ use Magento \Framework \View \Result \LayoutFactory ;
11
12
12
13
class AddComment extends \Magento \Backend \App \Action
13
14
{
@@ -21,18 +22,26 @@ class AddComment extends \Magento\Backend\App\Action
21
22
*/
22
23
protected $ shipmentSender ;
23
24
25
+ /**
26
+ * @var LayoutFactory
27
+ */
28
+ protected $ resultLayoutFactory ;
29
+
24
30
/**
25
31
* @param Action\Context $context
26
32
* @param \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
27
33
* @param ShipmentSender $shipmentSender
34
+ * @param LayoutFactory $resultLayoutFactory
28
35
*/
29
36
public function __construct (
30
37
Action \Context $ context ,
31
38
\Magento \Shipping \Controller \Adminhtml \Order \ShipmentLoader $ shipmentLoader ,
32
- ShipmentSender $ shipmentSender
39
+ ShipmentSender $ shipmentSender ,
40
+ LayoutFactory $ resultLayoutFactory
33
41
) {
34
42
$ this ->shipmentLoader = $ shipmentLoader ;
35
43
$ this ->shipmentSender = $ shipmentSender ;
44
+ $ this ->resultLayoutFactory = $ resultLayoutFactory ;
36
45
parent ::__construct ($ context );
37
46
}
38
47
@@ -72,10 +81,9 @@ public function execute()
72
81
73
82
$ this ->shipmentSender ->send ($ shipment , !empty ($ data ['is_customer_notified ' ]), $ data ['comment ' ]);
74
83
$ shipment ->save ();
75
-
76
- $ this ->_view ->loadLayout (false );
77
- $ this ->_view ->getPage ()->getConfig ()->getTitle ()->prepend (__ ('Shipments ' ));
78
- $ response = $ this ->_view ->getLayout ()->getBlock ('shipment_comments ' )->toHtml ();
84
+ $ resultLayout = $ this ->resultLayoutFactory ->create ();
85
+ $ resultLayout ->addDefaultHandle ();
86
+ $ response = $ resultLayout ->getLayout ()->getBlock ('shipment_comments ' )->toHtml ();
79
87
} catch (\Magento \Framework \Exception \LocalizedException $ e ) {
80
88
$ response = ['error ' => true , 'message ' => $ e ->getMessage ()];
81
89
} catch (\Exception $ e ) {
0 commit comments