View.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\RmaShipment;
  6. use Magento\Backend\Block\Widget\Container;
  7. use Magento\Backend\Block\Widget\Context;
  8. use Magento\Rma\Api\Data\RmaInterface;
  9. use Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  10. /**
  11. * RMA Shipment View
  12. *
  13. * @package Temando\Shipping\Block
  14. * @author Rhodri Davies <rhodri.davies@temando.com>
  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 View extends Container
  21. {
  22. /**
  23. * @var RmaAccess
  24. */
  25. private $rmaAccess;
  26. /**
  27. * View constructor.
  28. * @param Context $context
  29. * @param RmaAccess $rmaAccess
  30. * @param mixed[] $data
  31. */
  32. public function __construct(Context $context, RmaAccess $rmaAccess, array $data = [])
  33. {
  34. $this->rmaAccess = $rmaAccess;
  35. parent::__construct($context, $data);
  36. }
  37. /**
  38. * @param RmaInterface $rma
  39. * @return string
  40. */
  41. private function getBackUrl(RmaInterface $rma)
  42. {
  43. if (!$rma->getEntityId()) {
  44. $backUrl = $this->getUrl(
  45. 'adminhtml/order_shipment/view',
  46. ['shipment_id' => $this->getRequest()->getParam('shipment_id')]
  47. );
  48. } else {
  49. $backUrl = $this->getUrl('adminhtml/rma/edit', ['id' => $rma->getEntityId()]);
  50. }
  51. return $backUrl;
  52. }
  53. /**
  54. * @return \Magento\Backend\Block\Widget\Container
  55. */
  56. protected function _prepareLayout()
  57. {
  58. $rma = $this->rmaAccess->getCurrentRma();
  59. if (!$rma) {
  60. return parent::_prepareLayout();
  61. }
  62. $backUrl = $this->getBackUrl($rma);
  63. $dispatchCreateUrl = $this->getUrl('temando/rma_shipment/dispatch', [
  64. 'rma_id' => $rma->getEntityId(),
  65. 'ext_shipment_id' => $this->rmaAccess->getCurrentRmaShipment()->getShipmentId()
  66. ]);
  67. $this->addButton('back', [
  68. 'label' => __('Back'),
  69. 'class' => 'back',
  70. 'onclick' => sprintf("setLocation('%s')", $backUrl)
  71. ]);
  72. $this->addButton('temando_dispatch_return_shipment', [
  73. 'label' => __('Dispatch Shipment'),
  74. 'class' => 'primary',
  75. 'onclick' => sprintf("setLocation('%s')", $dispatchCreateUrl)
  76. ]);
  77. return parent::_prepareLayout();
  78. }
  79. /**
  80. * Prepare html output
  81. *
  82. * @return string
  83. */
  84. protected function _toHtml()
  85. {
  86. $html = parent::_toHtml();
  87. // append all child blocks
  88. $html.= $this->getChildHtml();
  89. return $html;
  90. }
  91. }