View.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Block\Adminhtml;
  7. /**
  8. * Adminhtml shipment create
  9. *
  10. * @api
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. * @since 100.0.2
  13. */
  14. class View extends \Magento\Backend\Block\Widget\Form\Container
  15. {
  16. /**
  17. * Core registry
  18. *
  19. * @var \Magento\Framework\Registry
  20. */
  21. protected $_coreRegistry = null;
  22. /**
  23. * @param \Magento\Backend\Block\Widget\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param array $data
  26. */
  27. public function __construct(
  28. \Magento\Backend\Block\Widget\Context $context,
  29. \Magento\Framework\Registry $registry,
  30. array $data = []
  31. ) {
  32. $this->_coreRegistry = $registry;
  33. parent::__construct($context, $data);
  34. }
  35. /**
  36. * @return void
  37. */
  38. protected function _construct()
  39. {
  40. $this->_objectId = 'shipment_id';
  41. $this->_mode = 'view';
  42. parent::_construct();
  43. $this->buttonList->remove('reset');
  44. $this->buttonList->remove('delete');
  45. if (!$this->getShipment()) {
  46. return;
  47. }
  48. if ($this->_authorization->isAllowed('Magento_Sales::emails')) {
  49. $this->buttonList->update('save', 'label', __('Send Tracking Information'));
  50. $this->buttonList->update(
  51. 'save',
  52. 'onclick',
  53. "deleteConfirm('" . __(
  54. 'Are you sure you want to send a Shipment email to customer?'
  55. ) . "', '" . $this->getEmailUrl() . "')"
  56. );
  57. }
  58. if ($this->getShipment()->getId()) {
  59. $this->buttonList->add(
  60. 'print',
  61. [
  62. 'label' => __('Print'),
  63. 'class' => 'save',
  64. 'onclick' => 'setLocation(\'' . $this->getPrintUrl() . '\')'
  65. ]
  66. );
  67. }
  68. }
  69. /**
  70. * Retrieve shipment model instance
  71. *
  72. * @return \Magento\Sales\Model\Order\Shipment
  73. */
  74. public function getShipment()
  75. {
  76. return $this->_coreRegistry->registry('current_shipment');
  77. }
  78. /**
  79. * @return \Magento\Framework\Phrase
  80. */
  81. public function getHeaderText()
  82. {
  83. if ($this->getShipment()->getEmailSent()) {
  84. $emailSent = __('the shipment email was sent');
  85. } else {
  86. $emailSent = __('the shipment email is not sent');
  87. }
  88. return __(
  89. 'Shipment #%1 | %3 (%2)',
  90. $this->getShipment()->getIncrementId(),
  91. $emailSent,
  92. $this->formatDate(
  93. $this->_localeDate->date(new \DateTime($this->getShipment()->getCreatedAt())),
  94. \IntlDateFormatter::MEDIUM,
  95. true
  96. )
  97. );
  98. }
  99. /**
  100. * @return string
  101. */
  102. public function getBackUrl()
  103. {
  104. return $this->getUrl(
  105. 'sales/order/view',
  106. [
  107. 'order_id' => $this->getShipment() ? $this->getShipment()->getOrderId() : null,
  108. 'active_tab' => 'order_shipments'
  109. ]
  110. );
  111. }
  112. /**
  113. * @return string
  114. */
  115. public function getEmailUrl()
  116. {
  117. return $this->getUrl('adminhtml/order_shipment/email', ['shipment_id' => $this->getShipment()->getId()]);
  118. }
  119. /**
  120. * @return string
  121. */
  122. public function getPrintUrl()
  123. {
  124. return $this->getUrl('sales/shipment/print', ['shipment_id' => $this->getShipment()->getId()]);
  125. }
  126. /**
  127. * @param bool $flag
  128. * @return $this
  129. */
  130. public function updateBackButtonUrl($flag)
  131. {
  132. if ($flag) {
  133. if ($this->getShipment()->getBackUrl()) {
  134. return $this->buttonList->update(
  135. 'back',
  136. 'onclick',
  137. 'setLocation(\'' . $this->getShipment()->getBackUrl() . '\')'
  138. );
  139. }
  140. return $this->buttonList->update(
  141. 'back',
  142. 'onclick',
  143. 'setLocation(\'' . $this->getUrl('sales/shipment/') . '\')'
  144. );
  145. }
  146. return $this;
  147. }
  148. }