Tracking.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Block\Adminhtml\Order;
  7. /**
  8. * Shipment tracking control form
  9. *
  10. * @api
  11. * @since 100.0.2
  12. */
  13. class Tracking extends \Magento\Backend\Block\Template
  14. {
  15. /**
  16. * Core registry
  17. *
  18. * @var \Magento\Framework\Registry
  19. */
  20. protected $_coreRegistry = null;
  21. /**
  22. * @var \Magento\Shipping\Model\Config
  23. */
  24. protected $_shippingConfig;
  25. /**
  26. * @param \Magento\Backend\Block\Template\Context $context
  27. * @param \Magento\Shipping\Model\Config $shippingConfig
  28. * @param \Magento\Framework\Registry $registry
  29. * @param array $data
  30. */
  31. public function __construct(
  32. \Magento\Backend\Block\Template\Context $context,
  33. \Magento\Shipping\Model\Config $shippingConfig,
  34. \Magento\Framework\Registry $registry,
  35. array $data = []
  36. ) {
  37. $this->_shippingConfig = $shippingConfig;
  38. $this->_coreRegistry = $registry;
  39. parent::__construct($context, $data);
  40. }
  41. /**
  42. * Prepares layout of block
  43. *
  44. * @return void
  45. */
  46. protected function _prepareLayout()
  47. {
  48. $this->addChild(
  49. 'add_button',
  50. \Magento\Backend\Block\Widget\Button::class,
  51. ['label' => __('Add Tracking Number'), 'class' => '', 'onclick' => 'trackingControl.add()']
  52. );
  53. }
  54. /**
  55. * Retrieve shipment model instance
  56. *
  57. * @return \Magento\Sales\Model\Order\Shipment
  58. */
  59. public function getShipment()
  60. {
  61. return $this->_coreRegistry->registry('current_shipment');
  62. }
  63. /**
  64. * Retrieve carriers
  65. *
  66. * @return array
  67. */
  68. public function getCarriers()
  69. {
  70. $carriers = [];
  71. $carrierInstances = $this->_getCarriersInstances();
  72. $carriers['custom'] = __('Custom Value');
  73. foreach ($carrierInstances as $code => $carrier) {
  74. if ($carrier->isTrackingAvailable()) {
  75. $carriers[$code] = $carrier->getConfigData('title');
  76. }
  77. }
  78. return $carriers;
  79. }
  80. /**
  81. * @return array
  82. */
  83. protected function _getCarriersInstances()
  84. {
  85. return $this->_shippingConfig->getAllCarriers($this->getShipment()->getStoreId());
  86. }
  87. }