Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
View.php
Go to the documentation of this file.
1 <?php
7 
15 class View extends \Magento\Backend\Block\Widget\Form\Container
16 {
22  protected $_coreRegistry = null;
23 
29  public function __construct(
30  \Magento\Backend\Block\Widget\Context $context,
31  \Magento\Framework\Registry $registry,
32  array $data = []
33  ) {
34  $this->_coreRegistry = $registry;
35  parent::__construct($context, $data);
36  }
37 
41  protected function _construct()
42  {
43  $this->_objectId = 'shipment_id';
44  $this->_mode = 'view';
45 
46  parent::_construct();
47 
48  $this->buttonList->remove('reset');
49  $this->buttonList->remove('delete');
50  if (!$this->getShipment()) {
51  return;
52  }
53 
54  if ($this->_authorization->isAllowed('Magento_Sales::emails')) {
55  $this->buttonList->update('save', 'label', __('Send Tracking Information'));
56  $this->buttonList->update(
57  'save',
58  'onclick',
59  "deleteConfirm('" . __(
60  'Are you sure you want to send a Shipment email to customer?'
61  ) . "', '" . $this->getEmailUrl() . "')"
62  );
63  }
64 
65  if ($this->getShipment()->getId()) {
66  $this->buttonList->add(
67  'print',
68  [
69  'label' => __('Print'),
70  'class' => 'save',
71  'onclick' => 'setLocation(\'' . $this->getPrintUrl() . '\')'
72  ]
73  );
74  }
75  }
76 
82  public function getShipment()
83  {
84  return $this->_coreRegistry->registry('current_shipment');
85  }
86 
90  public function getHeaderText()
91  {
92  if ($this->getShipment()->getEmailSent()) {
93  $emailSent = __('the shipment email was sent');
94  } else {
95  $emailSent = __('the shipment email is not sent');
96  }
97  return __(
98  'Shipment #%1 | %3 (%2)',
99  $this->getShipment()->getIncrementId(),
100  $emailSent,
101  $this->formatDate(
102  $this->_localeDate->date(new \DateTime($this->getShipment()->getCreatedAt())),
103  \IntlDateFormatter::MEDIUM,
104  true
105  )
106  );
107  }
108 
112  public function getBackUrl()
113  {
114  return $this->getUrl(
115  'sales/order/view',
116  [
117  'order_id' => $this->getShipment() ? $this->getShipment()->getOrderId() : null,
118  'active_tab' => 'order_shipments'
119  ]
120  );
121  }
122 
126  public function getEmailUrl()
127  {
128  return $this->getUrl('adminhtml/order_shipment/email', ['shipment_id' => $this->getShipment()->getId()]);
129  }
130 
134  public function getPrintUrl()
135  {
136  return $this->getUrl('sales/shipment/print', ['shipment_id' => $this->getShipment()->getId()]);
137  }
138 
143  public function updateBackButtonUrl($flag)
144  {
145  if ($flag) {
146  if ($this->getShipment()->getBackUrl()) {
147  return $this->buttonList->update(
148  'back',
149  'onclick',
150  'setLocation(\'' . $this->getShipment()->getBackUrl() . '\')'
151  );
152  }
153  return $this->buttonList->update(
154  'back',
155  'onclick',
156  'setLocation(\'' . $this->getUrl('sales/shipment/') . '\')'
157  );
158  }
159  return $this;
160  }
161 }
__()
Definition: __.php:13
__construct(\Magento\Backend\Block\Widget\Context $context, \Magento\Framework\Registry $registry, array $data=[])
Definition: View.php:29