Validatevat.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Adminhtml VAT ID validation block
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Customer\Block\Adminhtml\System\Config;
  12. class Validatevat extends \Magento\Config\Block\System\Config\Form\Field
  13. {
  14. /**
  15. * Merchant Country Field Name
  16. *
  17. * @var string
  18. */
  19. protected $_merchantCountry = 'general_store_information_country_id';
  20. /**
  21. * Merchant VAT Number Field
  22. *
  23. * @var string
  24. */
  25. protected $_merchantVatNumber = 'general_store_information_merchant_vat_number';
  26. /**
  27. * Validate VAT Button Label
  28. *
  29. * @var string
  30. */
  31. protected $_vatButtonLabel = 'Validate VAT Number';
  32. /**
  33. * Set Merchant Country Field Name
  34. *
  35. * @param string $countryField
  36. * @return \Magento\Customer\Block\Adminhtml\System\Config\Validatevat
  37. */
  38. public function setMerchantCountryField($countryField)
  39. {
  40. $this->_merchantCountry = $countryField;
  41. return $this;
  42. }
  43. /**
  44. * Get Merchant Country Field Name
  45. *
  46. * @return string
  47. */
  48. public function getMerchantCountryField()
  49. {
  50. return $this->_merchantCountry;
  51. }
  52. /**
  53. * Set Merchant VAT Number Field
  54. *
  55. * @param string $vatNumberField
  56. * @return \Magento\Customer\Block\Adminhtml\System\Config\Validatevat
  57. */
  58. public function setMerchantVatNumberField($vatNumberField)
  59. {
  60. $this->_merchantVatNumber = $vatNumberField;
  61. return $this;
  62. }
  63. /**
  64. * Get Merchant VAT Number Field
  65. *
  66. * @return string
  67. */
  68. public function getMerchantVatNumberField()
  69. {
  70. return $this->_merchantVatNumber;
  71. }
  72. /**
  73. * Set Validate VAT Button Label
  74. *
  75. * @param string $vatButtonLabel
  76. * @return \Magento\Customer\Block\Adminhtml\System\Config\Validatevat
  77. */
  78. public function setVatButtonLabel($vatButtonLabel)
  79. {
  80. $this->_vatButtonLabel = $vatButtonLabel;
  81. return $this;
  82. }
  83. /**
  84. * Set template to itself
  85. *
  86. * @return \Magento\Customer\Block\Adminhtml\System\Config\Validatevat
  87. */
  88. protected function _prepareLayout()
  89. {
  90. parent::_prepareLayout();
  91. if (!$this->getTemplate()) {
  92. $this->setTemplate('Magento_Customer::system/config/validatevat.phtml');
  93. }
  94. return $this;
  95. }
  96. /**
  97. * Unset some non-related element parameters
  98. *
  99. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  100. * @return string
  101. */
  102. public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  103. {
  104. $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
  105. return parent::render($element);
  106. }
  107. /**
  108. * Get the button and scripts contents
  109. *
  110. * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
  111. * @return string
  112. */
  113. protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
  114. {
  115. $originalData = $element->getOriginalData();
  116. $buttonLabel = !empty($originalData['button_label']) ? $originalData['button_label'] : $this->_vatButtonLabel;
  117. $this->addData(
  118. [
  119. 'button_label' => __($buttonLabel),
  120. 'html_id' => $element->getHtmlId(),
  121. 'ajax_url' => $this->_urlBuilder->getUrl('customer/system_config_validatevat/validate'),
  122. ]
  123. );
  124. return $this->_toHtml();
  125. }
  126. }