ValidateAdvanced.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Customer\Controller\Adminhtml\System\Config\Validatevat;
  8. class ValidateAdvanced extends \Magento\Customer\Controller\Adminhtml\System\Config\Validatevat
  9. {
  10. /**
  11. * @var \Magento\Framework\Controller\Result\JsonFactory
  12. */
  13. protected $resultJsonFactory;
  14. /**
  15. * @param \Magento\Backend\App\Action\Context $context
  16. * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
  17. */
  18. public function __construct(
  19. \Magento\Backend\App\Action\Context $context,
  20. \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
  21. ) {
  22. parent::__construct($context);
  23. $this->resultJsonFactory = $resultJsonFactory;
  24. }
  25. /**
  26. * Retrieve validation result as JSON
  27. *
  28. * @return \Magento\Framework\Controller\Result\Json
  29. */
  30. public function execute()
  31. {
  32. $result = $this->_validate();
  33. $valid = $result->getIsValid();
  34. $success = $result->getRequestSuccess();
  35. // ID of the store where order is placed
  36. $storeId = $this->getRequest()->getParam('store_id');
  37. // Sanitize value if needed
  38. if ($storeId !== null) {
  39. $storeId = (int)$storeId;
  40. }
  41. $groupId = $this->_objectManager->get(\Magento\Customer\Model\Vat::class)
  42. ->getCustomerGroupIdBasedOnVatNumber(
  43. $this->getRequest()->getParam('country'),
  44. $result,
  45. $storeId
  46. );
  47. /** @var \Magento\Framework\Controller\Result\Json $resultJson */
  48. $resultJson = $this->resultJsonFactory->create();
  49. return $resultJson->setData(['valid' => $valid, 'group' => $groupId, 'success' => $success]);
  50. }
  51. }