Items.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Block\Adminhtml\Create;
  7. /**
  8. * Adminhtml shipment items grid
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Items extends \Magento\Sales\Block\Adminhtml\Items\AbstractItems
  14. {
  15. /**
  16. * Sales data
  17. *
  18. * @var \Magento\Sales\Helper\Data
  19. */
  20. protected $_salesData;
  21. /**
  22. * @var \Magento\Shipping\Model\CarrierFactory
  23. */
  24. protected $_carrierFactory;
  25. /**
  26. * @param \Magento\Backend\Block\Template\Context $context
  27. * @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
  28. * @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
  29. * @param \Magento\Framework\Registry $registry
  30. * @param \Magento\Sales\Helper\Data $salesData
  31. * @param \Magento\Shipping\Model\CarrierFactory $carrierFactory
  32. * @param array $data
  33. */
  34. public function __construct(
  35. \Magento\Backend\Block\Template\Context $context,
  36. \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
  37. \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
  38. \Magento\Framework\Registry $registry,
  39. \Magento\Sales\Helper\Data $salesData,
  40. \Magento\Shipping\Model\CarrierFactory $carrierFactory,
  41. array $data = []
  42. ) {
  43. $this->_salesData = $salesData;
  44. $this->_carrierFactory = $carrierFactory;
  45. parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data);
  46. }
  47. /**
  48. * Retrieve invoice order
  49. *
  50. * @return \Magento\Sales\Model\Order
  51. */
  52. public function getOrder()
  53. {
  54. return $this->getShipment()->getOrder();
  55. }
  56. /**
  57. * Retrieve source
  58. *
  59. * @return \Magento\Sales\Model\Order\Shipment
  60. */
  61. public function getSource()
  62. {
  63. return $this->getShipment();
  64. }
  65. /**
  66. * Retrieve shipment model instance
  67. *
  68. * @return \Magento\Sales\Model\Order\Shipment
  69. */
  70. public function getShipment()
  71. {
  72. return $this->_coreRegistry->registry('current_shipment');
  73. }
  74. /**
  75. * Prepare child blocks
  76. *
  77. * @return string
  78. */
  79. protected function _beforeToHtml()
  80. {
  81. $this->addChild(
  82. 'submit_button',
  83. \Magento\Backend\Block\Widget\Button::class,
  84. [
  85. 'label' => __('Submit Shipment'),
  86. 'class' => 'save submit-button primary',
  87. 'onclick' => 'submitShipment(this);'
  88. ]
  89. );
  90. return parent::_beforeToHtml();
  91. }
  92. /**
  93. * Format given price
  94. *
  95. * @param float $price
  96. * @return string
  97. */
  98. public function formatPrice($price)
  99. {
  100. return $this->getShipment()->getOrder()->formatPrice($price);
  101. }
  102. /**
  103. * Retrieve HTML of update button
  104. *
  105. * @return string
  106. */
  107. public function getUpdateButtonHtml()
  108. {
  109. return $this->getChildHtml('update_button');
  110. }
  111. /**
  112. * Get url for update
  113. *
  114. * @return string
  115. */
  116. public function getUpdateUrl()
  117. {
  118. return $this->getUrl('sales/*/updateQty', ['order_id' => $this->getShipment()->getOrderId()]);
  119. }
  120. /**
  121. * Check possibility to send shipment email
  122. *
  123. * @return bool
  124. */
  125. public function canSendShipmentEmail()
  126. {
  127. return $this->_salesData->canSendNewShipmentEmail($this->getOrder()->getStore()->getId());
  128. }
  129. /**
  130. * Checks the possibility of creating shipping label by current carrier
  131. *
  132. * @return bool
  133. */
  134. public function canCreateShippingLabel()
  135. {
  136. $shippingCarrier = $this->_carrierFactory->create(
  137. $this->getOrder()->getShippingMethod(true)->getCarrierCode()
  138. );
  139. return $shippingCarrier && $shippingCarrier->isShippingLabelsAvailable();
  140. }
  141. }