Form.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Shipment view form
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Shipping\Block\Adminhtml\View;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Form extends \Magento\Sales\Block\Adminhtml\Order\AbstractOrder
  17. {
  18. /**
  19. * @var \Magento\Shipping\Model\CarrierFactory
  20. */
  21. protected $_carrierFactory;
  22. /**
  23. * @param \Magento\Backend\Block\Template\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param \Magento\Sales\Helper\Admin $adminHelper
  26. * @param \Magento\Shipping\Model\CarrierFactory $carrierFactory
  27. * @param array $data
  28. */
  29. public function __construct(
  30. \Magento\Backend\Block\Template\Context $context,
  31. \Magento\Framework\Registry $registry,
  32. \Magento\Sales\Helper\Admin $adminHelper,
  33. \Magento\Shipping\Model\CarrierFactory $carrierFactory,
  34. array $data = []
  35. ) {
  36. $this->_carrierFactory = $carrierFactory;
  37. parent::__construct($context, $registry, $adminHelper, $data);
  38. }
  39. /**
  40. * Retrieve shipment model instance
  41. *
  42. * @return \Magento\Sales\Model\Order\Shipment
  43. */
  44. public function getShipment()
  45. {
  46. return $this->_coreRegistry->registry('current_shipment');
  47. }
  48. /**
  49. * Retrieve invoice order
  50. *
  51. * @return \Magento\Sales\Model\Order
  52. */
  53. public function getOrder()
  54. {
  55. return $this->getShipment()->getOrder();
  56. }
  57. /**
  58. * Retrieve source
  59. *
  60. * @return \Magento\Sales\Model\Order\Shipment
  61. */
  62. public function getSource()
  63. {
  64. return $this->getShipment();
  65. }
  66. /**
  67. * Get create label button html
  68. *
  69. * @return string
  70. * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  71. */
  72. public function getCreateLabelButton()
  73. {
  74. $data['shipment_id'] = $this->getShipment()->getId();
  75. $url = $this->getUrl('adminhtml/order_shipment/createLabel', $data);
  76. return $this->getLayout()->createBlock(
  77. \Magento\Backend\Block\Widget\Button::class
  78. )->setData(
  79. [
  80. 'label' => __('Create Shipping Label...'),
  81. 'onclick' => 'packaging.showWindow();',
  82. 'class' => 'action-create-label'
  83. ]
  84. )->toHtml();
  85. }
  86. /**
  87. * Get print label button html
  88. *
  89. * @return string
  90. */
  91. public function getPrintLabelButton()
  92. {
  93. $data['shipment_id'] = $this->getShipment()->getId();
  94. $url = $this->getUrl('adminhtml/order_shipment/printLabel', $data);
  95. return $this->getLayout()->createBlock(
  96. \Magento\Backend\Block\Widget\Button::class
  97. )->setData(
  98. ['label' => __('Print Shipping Label'), 'onclick' => 'setLocation(\'' . $url . '\')']
  99. )->toHtml();
  100. }
  101. /**
  102. * Show packages button html
  103. *
  104. * @return string
  105. */
  106. public function getShowPackagesButton()
  107. {
  108. return $this->getLayout()->createBlock(
  109. \Magento\Backend\Block\Widget\Button::class
  110. )->setData(
  111. ['label' => __('Show Packages'), 'onclick' => 'showPackedWindow();']
  112. )->toHtml();
  113. }
  114. /**
  115. * Check is carrier has functionality of creation shipping labels
  116. *
  117. * @return bool
  118. */
  119. public function canCreateShippingLabel()
  120. {
  121. $shippingCarrier = $this->_carrierFactory->create(
  122. $this->getOrder()->getShippingMethod(true)->getCarrierCode()
  123. );
  124. return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable();
  125. }
  126. }