CheckoutFields.php 3.3 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\ViewModel\Config;
  6. use Magento\Framework\App\RequestInterface;
  7. use Magento\Framework\UrlInterface;
  8. use Magento\Framework\View\Element\Block\ArgumentInterface;
  9. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  10. use Temando\Shipping\ViewModel\DataProvider\ShippingApiAccess;
  11. use Temando\Shipping\ViewModel\DataProvider\ShippingApiAccessInterface;
  12. use Temando\Shipping\ViewModel\PageActionsInterface;
  13. use Temando\Shipping\ViewModel\ShippingApiInterface;
  14. /**
  15. * View model for checkout fields JS component.
  16. *
  17. * @package Temando\Shipping\ViewModel
  18. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  19. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  20. * @link http://www.temando.com/
  21. */
  22. class CheckoutFields implements ArgumentInterface, PageActionsInterface, ShippingApiInterface
  23. {
  24. /**
  25. * @var RequestInterface
  26. */
  27. private $request;
  28. /**
  29. * @var ShippingApiAccess
  30. */
  31. private $shippingApiAccess;
  32. /**
  33. * @var UrlInterface
  34. */
  35. private $urlBuilder;
  36. /**
  37. * @var ModuleConfigInterface
  38. */
  39. private $moduleConfig;
  40. /**
  41. * CheckoutFields constructor.
  42. * @param RequestInterface $request
  43. * @param ShippingApiAccess $shippingApiAccess
  44. * @param UrlInterface $urlBuilder
  45. * @param ModuleConfigInterface $moduleConfig
  46. */
  47. public function __construct(
  48. RequestInterface $request,
  49. ShippingApiAccess $shippingApiAccess,
  50. UrlInterface $urlBuilder,
  51. ModuleConfigInterface $moduleConfig
  52. ) {
  53. $this->request = $request;
  54. $this->shippingApiAccess = $shippingApiAccess;
  55. $this->urlBuilder = $urlBuilder;
  56. $this->moduleConfig = $moduleConfig;
  57. }
  58. /**
  59. * Obtain array of button data.
  60. *
  61. * @see \Temando\Shipping\Block\Adminhtml\ComponentContainer::_prepareLayout
  62. * @see \Magento\Backend\Block\Widget\Button\ButtonList::add
  63. *
  64. * @return mixed[][]
  65. */
  66. public function getMainActions(): array
  67. {
  68. $buttonId = 'back';
  69. $buttonData = [
  70. 'label' => __('Back'),
  71. 'onclick' => sprintf("window.location.href = '%s';", $this->getConfigurationPageUrl()),
  72. 'class' => 'back',
  73. 'sort_order' => 10
  74. ];
  75. $mainActions = [
  76. $buttonId => $buttonData,
  77. ];
  78. return $mainActions;
  79. }
  80. /**
  81. * @return ShippingApiAccessInterface
  82. */
  83. public function getShippingApiAccess(): ShippingApiAccessInterface
  84. {
  85. return $this->shippingApiAccess;
  86. }
  87. /**
  88. * @return string
  89. */
  90. public function getUpdateCheckoutFieldEndpoint(): string
  91. {
  92. return $this->urlBuilder->getUrl('temando/settings_checkout/save');
  93. }
  94. /**
  95. * @return string
  96. */
  97. public function getConfigurationPageUrl(): string
  98. {
  99. return $this->urlBuilder->getUrl('adminhtml/system_config/edit', [
  100. 'section' => 'carriers',
  101. '_fragment' => 'carriers_temando-link',
  102. ]);
  103. }
  104. /**
  105. * @return string
  106. */
  107. public function getCheckoutFieldsData(): string
  108. {
  109. return $this->moduleConfig->getCheckoutFieldsDefinition();
  110. }
  111. }