Documentation.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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;
  6. use Magento\Backend\Block\Template as BackendTemplate;
  7. use Magento\Backend\Block\Template\Context;
  8. use Temando\Shipping\Model\DispatchProviderInterface;
  9. use Temando\Shipping\Model\DocumentationInterface;
  10. use Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  11. use Temando\Shipping\Model\Shipment\ShipmentProviderInterface;
  12. /**
  13. * Temando Documentation Listing Layout Block
  14. *
  15. * @package Temando\Shipping\Block
  16. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  17. * @author Rhodri Davies <rhodri.davies@temando.com>
  18. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  19. * @link http://www.temando.com/
  20. *
  21. * @api
  22. * @deprecated since 1.1.3 | Block data is provided by view model
  23. * @see \Temando\Shipping\ViewModel\Shipment\ShipmentDetails
  24. */
  25. class Documentation extends BackendTemplate
  26. {
  27. /**
  28. * @var ShipmentProviderInterface
  29. */
  30. private $shipmentProvider;
  31. /**
  32. * @var DispatchProviderInterface
  33. */
  34. private $dispatchProvider;
  35. /**
  36. * @var RmaAccess
  37. */
  38. private $rmaAccess;
  39. /**
  40. * @param Context $context
  41. * @param ShipmentProviderInterface $shipmentProvider
  42. * @param DispatchProviderInterface $dispatchProvider
  43. * @param RmaAccess $rmaAccess
  44. * @param mixed[] $data
  45. */
  46. public function __construct(
  47. Context $context,
  48. ShipmentProviderInterface $shipmentProvider,
  49. DispatchProviderInterface $dispatchProvider,
  50. RmaAccess $rmaAccess,
  51. array $data = []
  52. ) {
  53. $this->shipmentProvider = $shipmentProvider;
  54. $this->dispatchProvider = $dispatchProvider;
  55. $this->rmaAccess = $rmaAccess;
  56. parent::__construct($context, $data);
  57. }
  58. /**
  59. * Set documentation from
  60. * - dispatch
  61. * - shipment or
  62. * - rma shipment
  63. *
  64. * @return BackendTemplate
  65. */
  66. protected function _beforeToHtml()
  67. {
  68. if (!$this->hasData('documentation')) {
  69. if ($this->dispatchProvider->getDispatch()) {
  70. $dispatch = $this->dispatchProvider->getDispatch();
  71. $this->setData('documentation', $dispatch->getDocumentation());
  72. } elseif ($this->shipmentProvider->getShipment()) {
  73. $shipment = $this->shipmentProvider->getShipment();
  74. $this->setData('documentation', $shipment->getDocumentation());
  75. } elseif ($this->rmaAccess->getCurrentRmaShipment()) {
  76. $shipment = $this->rmaAccess->getCurrentRmaShipment();
  77. $this->setData('documentation', $shipment->getDocumentation());
  78. }
  79. }
  80. return parent::_beforeToHtml();
  81. }
  82. /**
  83. * @return DocumentationInterface[]
  84. */
  85. public function getDocumentation()
  86. {
  87. return $this->hasData('documentation') ? $this->getData('documentation') : [];
  88. }
  89. /**
  90. * @param DocumentationInterface $documentation
  91. * @return \Magento\Framework\Phrase
  92. */
  93. public function getDisplayName(DocumentationInterface $documentation)
  94. {
  95. $fileTypeNames = [
  96. 'nafta' => 'NAFTA',
  97. 'certificateOfOrigin' => 'Certificate Of Origin',
  98. 'cn22' => 'CN 22',
  99. 'cn23' => 'CN 23',
  100. 'codTurnInPage' => 'Cash On Delivery Turn In Page',
  101. 'commercialInvoice' => 'Commercial Invoice',
  102. 'customerInvoice' => 'Customer Invoice',
  103. 'highValueReport' => 'High Value Report',
  104. 'manifestSummary' => 'Manifest Summary',
  105. 'packageLabel' => 'Package Label',
  106. 'packageReturnLabel' => 'Package Return Label',
  107. 'packagingList' => 'Packaging List',
  108. 'proofOfDelivery' => 'Proof Of Delivery'
  109. ];
  110. $displayName = isset($fileTypeNames[$documentation->getType()])
  111. ? $fileTypeNames[$documentation->getType()]
  112. : $documentation->getType();
  113. return __($displayName);
  114. }
  115. /**
  116. * @return bool
  117. */
  118. public function isPaperless()
  119. {
  120. /** @var \Temando\Shipping\Model\ShipmentInterface $shipment */
  121. $shipment = $this->shipmentProvider->getShipment();
  122. if ($shipment) {
  123. $originCountryCode = $shipment->getOriginLocation()->getCountryCode();
  124. $destinationCountryCode = $shipment->getDestinationLocation()->getCountryCode();
  125. if (($originCountryCode != $destinationCountryCode) && $shipment->isPaperless()) {
  126. return true;
  127. }
  128. }
  129. return false;
  130. }
  131. }