Tracking.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\ViewModel\Rma\RmaShipment;
  6. use Magento\Framework\UrlInterface;
  7. use Magento\Framework\View\Element\Block\ArgumentInterface;
  8. use Magento\Rma\Api\Data\RmaInterface;
  9. use Magento\Sales\Api\Data\OrderInterface;
  10. use Temando\Shipping\Model\ResourceModel\Rma\RmaAccess;
  11. use Temando\Shipping\Model\Shipment;
  12. use Temando\Shipping\Model\Shipment\FulfillmentInterface;
  13. use Temando\Shipping\Model\ShipmentInterface;
  14. use Temando\Shipping\Model\Shipping\Carrier;
  15. use Temando\Shipping\ViewModel\RmaAccessInterface;
  16. /**
  17. * View model for Rma Tracking.
  18. *
  19. * @package Temando\Shipping\ViewModel
  20. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  21. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  22. * @link http://www.temando.com/
  23. */
  24. class Tracking implements ArgumentInterface, RmaAccessInterface
  25. {
  26. /**
  27. * @var UrlInterface
  28. */
  29. private $urlBuilder;
  30. /**
  31. * @var Carrier
  32. */
  33. private $carrier;
  34. /**
  35. * @var RmaAccess
  36. */
  37. private $rmaAccess;
  38. /**
  39. * RmaView constructor.
  40. * @param RmaAccess $rmaAccess
  41. * @param UrlInterface $urlBuilder
  42. * @param Carrier $carrier
  43. */
  44. public function __construct(
  45. RmaAccess $rmaAccess,
  46. UrlInterface $urlBuilder,
  47. Carrier $carrier
  48. ) {
  49. $this->urlBuilder = $urlBuilder;
  50. $this->carrier = $carrier;
  51. $this->rmaAccess = $rmaAccess;
  52. }
  53. /**
  54. * @return string
  55. */
  56. public function getCarrierName()
  57. {
  58. return $this->carrier->getConfigData('title');
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function getTrackingNumber()
  64. {
  65. /** @var Shipment $shipment */
  66. $shipment = $this->rmaAccess->getCurrentRmaShipment();
  67. if (!$shipment->getFulfillment() instanceof FulfillmentInterface) {
  68. return '';
  69. }
  70. return $shipment->getFulfillment()->getTrackingReference();
  71. }
  72. /**
  73. * @return string
  74. */
  75. public function getCarrierTitle()
  76. {
  77. $shipment = $this->rmaAccess->getCurrentRmaShipment();
  78. if (!$shipment->getFulfillment() instanceof FulfillmentInterface) {
  79. return $this->getCarrierName();
  80. }
  81. $carrierTitle = sprintf(
  82. '%s - %s',
  83. $shipment->getFulfillment()->getCarrierName(),
  84. $shipment->getFulfillment()->getServiceName()
  85. );
  86. return $carrierTitle;
  87. }
  88. /**
  89. * Get tracking popup URL.
  90. */
  91. public function getTrackingPopUrl()
  92. {
  93. return $this->urlBuilder->getUrl(
  94. 'temando/rma_shipment/track',
  95. [
  96. 'shipment_id' => $this->rmaAccess->getCurrentRmaShipment()->getShipmentId(),
  97. '_secure' => true,
  98. ]
  99. );
  100. }
  101. /**
  102. * @return OrderInterface
  103. */
  104. public function getOrder(): OrderInterface
  105. {
  106. /** @var \Magento\Rma\Model\Rma $rma */
  107. $rma = $this->getRma();
  108. return $rma->getOrder();
  109. }
  110. /**
  111. * @return RmaInterface
  112. */
  113. public function getRma(): RmaInterface
  114. {
  115. return $this->rmaAccess->getCurrentRma();
  116. }
  117. /**
  118. * @deprecated since 1.2.0 | no longer available
  119. * @return ShipmentInterface
  120. */
  121. public function getRmaShipment(): ShipmentInterface
  122. {
  123. return $this->rmaAccess->getCurrentRmaShipment();
  124. }
  125. /**
  126. * Check if Return Shipment Exists.
  127. *
  128. * @return boolean
  129. */
  130. public function hasReturnShipment()
  131. {
  132. $returnShipment = $this->rmaAccess->getCurrentRmaShipment();
  133. return $returnShipment ? true : false;
  134. }
  135. /**
  136. * @return string
  137. */
  138. public function getShippingDescription()
  139. {
  140. $order = $this->getOrder();
  141. if (!$order) {
  142. return '';
  143. }
  144. return $order->getShippingDescription();
  145. }
  146. }