Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RemoveTrack.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
18  const ADMIN_RESOURCE = 'Magento_Sales::shipment';
19 
23  protected $shipmentLoader;
24 
29  public function __construct(
30  Action\Context $context,
31  \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader
32  ) {
33  $this->shipmentLoader = $shipmentLoader;
34  parent::__construct($context);
35  }
36 
42  public function execute()
43  {
44  $trackId = $this->getRequest()->getParam('track_id');
46  $track = $this->_objectManager->create(\Magento\Sales\Model\Order\Shipment\Track::class)->load($trackId);
47  if ($track->getId()) {
48  try {
49  $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
50  $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
51  $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
52  $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
53  $shipment = $this->shipmentLoader->load();
54  if ($shipment) {
55  $track->delete();
56 
57  $this->_view->loadLayout();
58  $this->_view->getPage()->getConfig()->getTitle()->prepend(__('Shipments'));
59  $response = $this->_view->getLayout()->getBlock('shipment_tracking')->toHtml();
60  } else {
61  $response = [
62  'error' => true,
63  'message' => __('We can\'t initialize shipment for delete tracking number.'),
64  ];
65  }
66  } catch (\Exception $e) {
67  $response = ['error' => true, 'message' => __('We can\'t delete tracking number.')];
68  }
69  } else {
70  $response = [
71  'error' => true,
72  'message' => __('We can\'t load track with retrieving identifier right now.')
73  ];
74  }
75  if (is_array($response)) {
76  $response = $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($response);
77  $this->getResponse()->representJson($response);
78  } else {
79  $this->getResponse()->setBody($response);
80  }
81  }
82 }
$response
Definition: 404.php:11
$track
Definition: details.phtml:12
__()
Definition: __.php:13
__construct(Action\Context $context, \Magento\Shipping\Controller\Adminhtml\Order\ShipmentLoader $shipmentLoader)
Definition: RemoveTrack.php:29
foreach($order->getItems() as $orderItem) $shipment