CheckoutFieldsComponent.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\Configuration;
  6. use Magento\Backend\Block\Widget\Context as WidgetContext;
  7. use Magento\Backend\Model\Auth\StorageInterface;
  8. use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
  9. use Magento\Framework\Stdlib\DateTime\DateTime;
  10. use Magento\Integration\Model\Oauth\Token;
  11. use Magento\Security\Model\Config;
  12. use Temando\Shipping\Block\Adminhtml\Template\AbstractComponent;
  13. use Temando\Shipping\Model\Config\ModuleConfigInterface;
  14. use Temando\Shipping\Rest\AuthenticationInterface;
  15. use Temando\Shipping\Webservice\Config\WsConfigInterface;
  16. /**
  17. * Temando Checkout Fields Component Block
  18. *
  19. * @package Temando\Shipping\Block
  20. * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
  21. * @author Rhodri Davies <rhodri.davies@temando.com>
  22. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  23. * @link http://www.temando.com/
  24. *
  25. * @api
  26. * @deprecated since 1.0.5 | Block data is provided by view model
  27. * @see \Temando\Shipping\ViewModel\Config\CheckoutFields
  28. */
  29. class CheckoutFieldsComponent extends AbstractComponent
  30. {
  31. /**
  32. * @var ModuleConfigInterface
  33. */
  34. private $moduleConfig;
  35. /**
  36. * CheckoutFieldsComponent constructor.
  37. * @param WidgetContext $context
  38. * @param WsConfigInterface $config
  39. * @param StorageInterface $session
  40. * @param AuthenticationInterface $auth
  41. * @param Token $token
  42. * @param DateTime $dateTime
  43. * @param RemoteAddress $remoteAddress
  44. * @param Config $securityConfig
  45. * @param ModuleConfigInterface $moduleConfig
  46. * @param mixed[] $data
  47. */
  48. public function __construct(
  49. WidgetContext $context,
  50. WsConfigInterface $config,
  51. StorageInterface $session,
  52. AuthenticationInterface $auth,
  53. Token $token,
  54. DateTime $dateTime,
  55. RemoteAddress $remoteAddress,
  56. Config $securityConfig,
  57. ModuleConfigInterface $moduleConfig,
  58. array $data = []
  59. ) {
  60. $this->moduleConfig = $moduleConfig;
  61. parent::__construct(
  62. $context,
  63. $config,
  64. $session,
  65. $auth,
  66. $token,
  67. $dateTime,
  68. $remoteAddress,
  69. $securityConfig,
  70. $data
  71. );
  72. }
  73. /**
  74. * Add Back Button.
  75. *
  76. * @return \Magento\Backend\Block\Widget\Container
  77. */
  78. protected function _prepareLayout()
  79. {
  80. $buttonData = [
  81. 'label' => __('Back'),
  82. 'onclick' => sprintf("window.location.href = '%s';", $this->getConfigurationPageUrl()),
  83. 'class' => 'back',
  84. 'sort_order' => 10
  85. ];
  86. $this->buttonList->add('back', $buttonData);
  87. return parent::_prepareLayout();
  88. }
  89. /**
  90. * @return string
  91. */
  92. public function getUpdateCheckoutFieldEndpoint()
  93. {
  94. return $this->getUrl('temando/settings_checkout/save');
  95. }
  96. /**
  97. * @return string
  98. */
  99. public function getConfigurationPageUrl()
  100. {
  101. return $this->getUrl('adminhtml/system_config/edit', [
  102. 'section' => 'carriers',
  103. '_fragment' => 'carriers_temando-link',
  104. ]);
  105. }
  106. /**
  107. * @return string
  108. */
  109. public function getCheckoutFieldsData()
  110. {
  111. return $this->moduleConfig->getCheckoutFieldsDefinition();
  112. }
  113. }