Solve.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Dispatch;
  6. use Magento\Backend\Block\Widget\Container;
  7. use Magento\Backend\Block\Widget\Context;
  8. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  9. use Temando\Shipping\Model\DispatchProviderInterface;
  10. /**
  11. * Temando Dispatch Solve Layout Block
  12. *
  13. * @package Temando\Shipping\Block
  14. * @author Max Melzer <max.melzer@netresearch.de>
  15. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  16. * @link http://www.temando.com/
  17. *
  18. * @api
  19. */
  20. class Solve extends Container
  21. {
  22. /**
  23. * @var ModuleConfigInterface
  24. */
  25. private $config;
  26. /**
  27. * @var DispatchProviderInterface
  28. */
  29. private $dispatchProvider;
  30. /**
  31. * Solve constructor.
  32. *
  33. * @param Context $context
  34. * @param ModuleConfigInterface $config
  35. * @param DispatchProviderInterface $dispatchProvider
  36. * @param mixed[] $data
  37. */
  38. public function __construct(
  39. Context $context,
  40. ModuleConfigInterface $config,
  41. DispatchProviderInterface $dispatchProvider,
  42. array $data = []
  43. ) {
  44. $this->config = $config;
  45. $this->dispatchProvider = $dispatchProvider;
  46. parent::__construct($context, $data);
  47. }
  48. /**
  49. * Add Back Button.
  50. *
  51. * @return \Magento\Framework\View\Element\AbstractBlock
  52. */
  53. protected function _prepareLayout()
  54. {
  55. $buttonData = [
  56. 'label' => __('Back'),
  57. 'onclick' => 'setLocation(\'' . $this->getBackUrl() . '\')',
  58. 'class' => 'back',
  59. ];
  60. $this->addButton('back', $buttonData, -1);
  61. return parent::_prepareLayout();
  62. }
  63. /**
  64. * @return \Temando\Shipping\Model\Dispatch\ShipmentInterface[]
  65. */
  66. public function getFailedShipments()
  67. {
  68. $dispatch = $this->dispatchProvider->getDispatch();
  69. if (!$dispatch) {
  70. return [];
  71. }
  72. return $dispatch->getFailedShipments();
  73. }
  74. /**
  75. * @return string
  76. */
  77. public function getBackUrl()
  78. {
  79. $dispatch = $this->dispatchProvider->getDispatch();
  80. if (!$dispatch) {
  81. return $this->_urlBuilder->getUrl('temando/dispatch/index');
  82. }
  83. return $this->_urlBuilder->getUrl('temando/dispatch/view', [
  84. 'dispatch_id' => $dispatch->getDispatchId()
  85. ]);
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function getNewUrl()
  91. {
  92. return $this->_urlBuilder->getUrl('temando/dispatch/new');
  93. }
  94. /**
  95. * @param string $extShipmentId
  96. * @return string
  97. */
  98. public function getShipmentUrl($extShipmentId)
  99. {
  100. return $this->_urlBuilder->getUrl('temando/shipment/view', ['shipment_id' => $extShipmentId]);
  101. }
  102. /**
  103. * @return string
  104. */
  105. public function getShippingPortalUrl()
  106. {
  107. return $this->config->getShippingPortalUrl();
  108. }
  109. }