Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Form.php
Go to the documentation of this file.
1 <?php
13 
18 class Form extends \Magento\Sales\Block\Adminhtml\Order\AbstractOrder
19 {
23  protected $_carrierFactory;
24 
32  public function __construct(
33  \Magento\Backend\Block\Template\Context $context,
34  \Magento\Framework\Registry $registry,
35  \Magento\Sales\Helper\Admin $adminHelper,
36  \Magento\Shipping\Model\CarrierFactory $carrierFactory,
37  array $data = []
38  ) {
39  $this->_carrierFactory = $carrierFactory;
40  parent::__construct($context, $registry, $adminHelper, $data);
41  }
42 
48  public function getShipment()
49  {
50  return $this->_coreRegistry->registry('current_shipment');
51  }
52 
58  public function getOrder()
59  {
60  return $this->getShipment()->getOrder();
61  }
62 
68  public function getSource()
69  {
70  return $this->getShipment();
71  }
72 
79  public function getCreateLabelButton()
80  {
81  $data['shipment_id'] = $this->getShipment()->getId();
82  $url = $this->getUrl('adminhtml/order_shipment/createLabel', $data);
83  return $this->getLayout()->createBlock(
84  \Magento\Backend\Block\Widget\Button::class
85  )->setData(
86  [
87  'label' => __('Create Shipping Label...'),
88  'onclick' => 'packaging.showWindow();',
89  'class' => 'action-create-label'
90  ]
91  )->toHtml();
92  }
93 
99  public function getPrintLabelButton()
100  {
101  $data['shipment_id'] = $this->getShipment()->getId();
102  $url = $this->getUrl('adminhtml/order_shipment/printLabel', $data);
103  return $this->getLayout()->createBlock(
104  \Magento\Backend\Block\Widget\Button::class
105  )->setData(
106  ['label' => __('Print Shipping Label'), 'onclick' => 'setLocation(\'' . $url . '\')']
107  )->toHtml();
108  }
109 
115  public function getShowPackagesButton()
116  {
117  return $this->getLayout()->createBlock(
118  \Magento\Backend\Block\Widget\Button::class
119  )->setData(
120  ['label' => __('Show Packages'), 'onclick' => 'showPackedWindow();']
121  )->toHtml();
122  }
123 
129  public function canCreateShippingLabel()
130  {
131  $shippingCarrier = $this->_carrierFactory->create(
132  $this->getOrder()->getShippingMethod(true)->getCarrierCode()
133  );
134  return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable();
135  }
136 }
__construct(\Magento\Backend\Block\Template\Context $context, \Magento\Framework\Registry $registry, \Magento\Sales\Helper\Admin $adminHelper, \Magento\Shipping\Model\CarrierFactory $carrierFactory, array $data=[])
Definition: Form.php:32
__()
Definition: __.php:13