Shipments.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Block\Adminhtml\Rma\Edit\Tab;
  6. use Magento\Backend\Block\Template\Context;
  7. use Magento\Backend\Block\Widget;
  8. use Magento\Backend\Block\Widget\Tab\TabInterface;
  9. use Magento\Framework\Registry;
  10. use Magento\Sales\Api\Data\OrderInterface;
  11. use Magento\Sales\Model\Order;
  12. use Temando\Shipping\Model\Shipping\Carrier;
  13. /**
  14. * RMA Shipments Tab
  15. *
  16. * @package Temando\Shipping\Block
  17. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  18. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. * @link https://www.temando.com/
  20. *
  21. * @api
  22. */
  23. class Shipments extends Widget implements TabInterface
  24. {
  25. /**
  26. * @var Registry
  27. */
  28. private $registry;
  29. /**
  30. * @param Context $context
  31. * @param Registry $registry
  32. * @param mixed[] $data
  33. */
  34. public function __construct(
  35. Context $context,
  36. Registry $registry,
  37. array $data = []
  38. ) {
  39. $this->registry = $registry;
  40. parent::__construct($context, $data);
  41. }
  42. /**
  43. * Get Header Text for Order Selection
  44. *
  45. * @return \Magento\Framework\Phrase
  46. */
  47. public function getHeaderText()
  48. {
  49. return __('Return Shipments');
  50. }
  51. /**
  52. * Prepare label for tab
  53. *
  54. * @return \Magento\Framework\Phrase
  55. */
  56. public function getTabLabel()
  57. {
  58. return __('Return Shipments');
  59. }
  60. /**
  61. * Prepare tab title
  62. *
  63. * @return string
  64. */
  65. public function getTabTitle()
  66. {
  67. return $this->getTabLabel();
  68. }
  69. /**
  70. * Can show tab in tabs
  71. *
  72. * @return true
  73. */
  74. public function canShowTab()
  75. {
  76. // only display if original order was shipped with temando shipping
  77. /** @var Order $order */
  78. $order = $this->registry->registry('current_order');
  79. if (!$order instanceof OrderInterface || !$order->getData('shipping_method')) {
  80. // wrong type, virtual or corrupt order
  81. return false;
  82. }
  83. $shippingMethod = $order->getShippingMethod(true);
  84. $carrierCode = $shippingMethod->getData('carrier_code');
  85. return ($carrierCode === Carrier::CODE);
  86. }
  87. /**
  88. * Returns status flag about this tab hidden or not
  89. *
  90. * @return true
  91. */
  92. public function isHidden()
  93. {
  94. return !$this->canShowTab();
  95. }
  96. }