AjaxLoad.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Tax\Controller\Adminhtml\Rate;
  8. use Magento\Framework\Exception\NoSuchEntityException;
  9. use Magento\Framework\Controller\ResultFactory;
  10. class AjaxLoad extends \Magento\Tax\Controller\Adminhtml\Rate
  11. {
  12. /**
  13. * Json needed for the Ajax Edit Form
  14. *
  15. * @return \Magento\Framework\Controller\Result\Json
  16. * @throws \InvalidArgumentException
  17. */
  18. public function execute()
  19. {
  20. $rateId = (int)$this->getRequest()->getParam('id');
  21. try {
  22. /* @var \Magento\Tax\Api\Data\TaxRateInterface */
  23. $taxRateDataObject = $this->_taxRateRepository->get($rateId);
  24. /* @var array */
  25. $resultArray = $this->_taxRateConverter->createArrayFromServiceObject($taxRateDataObject, true);
  26. $responseContent = [
  27. 'success' => true,
  28. 'error_message' => '',
  29. 'result' => $resultArray,
  30. ];
  31. } catch (NoSuchEntityException $e) {
  32. $responseContent = [
  33. 'success' => false,
  34. 'error_message' => $e->getMessage(),
  35. ];
  36. } catch (\Exception $e) {
  37. $responseContent = [
  38. 'success' => false,
  39. 'error_message' => __('An error occurred while loading this tax rate.'),
  40. ];
  41. }
  42. /** @var \Magento\Framework\Controller\Result\Json $resultJson */
  43. $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
  44. $resultJson->setData($responseContent);
  45. return $resultJson;
  46. }
  47. }