PickupUrl.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\ViewModel\DataProvider;
  6. use Magento\Framework\App\ActionInterface;
  7. use Magento\Framework\App\Response\RedirectInterface;
  8. use Magento\Framework\Url\EncoderInterface;
  9. use Magento\Framework\UrlInterface;
  10. use Temando\Shipping\Model\PickupInterface;
  11. /**
  12. * Pickup Fulfillment URL provider
  13. *
  14. * @package Temando\Shipping\ViewModel
  15. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  16. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  17. * @link https://www.temando.com/
  18. */
  19. class PickupUrl implements EntityUrlInterface
  20. {
  21. /**
  22. * Url Builder
  23. *
  24. * @var UrlInterface
  25. */
  26. private $urlBuilder;
  27. /**
  28. * @var RedirectInterface
  29. */
  30. private $redirect;
  31. /**
  32. * @var EncoderInterface
  33. */
  34. private $encoder;
  35. /**
  36. * PickupUrl constructor.
  37. * @param UrlInterface $urlBuilder
  38. * @param RedirectInterface $redirect
  39. * @param EncoderInterface $encoder
  40. */
  41. public function __construct(
  42. UrlInterface $urlBuilder,
  43. RedirectInterface $redirect,
  44. EncoderInterface $encoder
  45. ) {
  46. $this->urlBuilder = $urlBuilder;
  47. $this->redirect = $redirect;
  48. $this->encoder = $encoder;
  49. }
  50. /**
  51. * Creating pickup fulfillments via UI is not supported.
  52. *
  53. * @return string
  54. */
  55. public function getNewActionUrl(): string
  56. {
  57. return '';
  58. }
  59. /**
  60. * Link to the pickup fulfillment grid listing
  61. *
  62. * @return string
  63. */
  64. public function getListActionUrl(): string
  65. {
  66. return $this->urlBuilder->getUrl('temando/pickup/index');
  67. }
  68. /**
  69. * Link to the "Prepare for Pickup" page with editable quantities.
  70. *
  71. * @param mixed[] $data Item data to pick entity identifiers.
  72. * @return string
  73. */
  74. public function getEditActionUrl(array $data): string
  75. {
  76. return $this->urlBuilder->getUrl('temando/pickup/prepare', [
  77. 'pickup_id' => $data[PickupInterface::PICKUP_ID],
  78. 'sales_order_id' => $data[PickupInterface::SALES_ORDER_ID],
  79. ]);
  80. }
  81. /**
  82. * Link to the pickup detail view.
  83. *
  84. * @param mixed[] $data Item data to pick entity identifier.
  85. * @return string
  86. */
  87. public function getViewActionUrl(array $data): string
  88. {
  89. return $this->urlBuilder->getUrl('temando/pickup/view', [
  90. 'pickup_id' => $data[PickupInterface::PICKUP_ID],
  91. 'sales_order_id' => $data[PickupInterface::SALES_ORDER_ID],
  92. ]);
  93. }
  94. /**
  95. * Link to the pickup forward action with placeholder.
  96. *
  97. * @return string
  98. */
  99. public function getForwardActionUrl(): string
  100. {
  101. return $this->urlBuilder->getUrl('temando/pickup/forward', ['pickup_id' => '--id--']);
  102. }
  103. /**
  104. * Link to the "mark as ready for pickup" POST action
  105. *
  106. * @param mixed[] $data Item data to pick entity identifiers.
  107. * @return string
  108. */
  109. public function getReadyActionUrl(array $data): string
  110. {
  111. $uenc = $this->encoder->encode($this->redirect->getRefererUrl());
  112. $routeParams = [];
  113. $routeParams['pickup_id'] = $data[PickupInterface::PICKUP_ID];
  114. $routeParams['sales_order_id'] = $data[PickupInterface::SALES_ORDER_ID];
  115. $routeParams[ActionInterface::PARAM_NAME_URL_ENCODED] = $uenc;
  116. return $this->urlBuilder->getUrl('temando/pickup/ready', $routeParams);
  117. }
  118. /**
  119. * Link to the "mark as picked up" POST action
  120. *
  121. * @param mixed[] $data Item data for the implementer to pick entity identifier.
  122. * @return string
  123. */
  124. public function getCollectedActionUrl(array $data): string
  125. {
  126. $uenc = $this->encoder->encode($this->redirect->getRefererUrl());
  127. $routeParams = [];
  128. $routeParams['pickup_id'] = $data[PickupInterface::PICKUP_ID];
  129. $routeParams['sales_order_id'] = $data[PickupInterface::SALES_ORDER_ID];
  130. $routeParams[ActionInterface::PARAM_NAME_URL_ENCODED] = $uenc;
  131. return $this->urlBuilder->getUrl('temando/pickup/collected', $routeParams);
  132. }
  133. /**
  134. * Link to the pickup cancel POST action.
  135. *
  136. * @param mixed[] $data Item data for the implementer to pick entity identifier.
  137. * @return string
  138. */
  139. public function getDeleteActionUrl(array $data): string
  140. {
  141. $uenc = $this->encoder->encode($this->redirect->getRefererUrl());
  142. $routeParams = [];
  143. $routeParams['pickup_id'] = $data[PickupInterface::PICKUP_ID];
  144. $routeParams['sales_order_id'] = $data[PickupInterface::SALES_ORDER_ID];
  145. $routeParams[ActionInterface::PARAM_NAME_URL_ENCODED] = $uenc;
  146. return $this->urlBuilder->getUrl('temando/pickup/cancel', $routeParams);
  147. }
  148. /**
  149. * Link to the pickup print action.
  150. *
  151. * @param mixed[] $data Item data for the implementer to pick entity identifier.
  152. * @return string
  153. */
  154. public function getPrintActionUrl(array $data): string
  155. {
  156. return $this->urlBuilder->getUrl('temando/pickup/print', [
  157. 'pickup_id' => $data[PickupInterface::PICKUP_ID],
  158. 'sales_order_id' => $data[PickupInterface::SALES_ORDER_ID],
  159. ]);
  160. }
  161. }