Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AjaxSave.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
19  public function execute()
20  {
21  try {
22  $rateData = $this->_processRateData($this->getRequest()->getPostValue());
24  $taxRate = $this->_taxRateConverter->populateTaxRateData($rateData);
25  $this->_taxRateRepository->save($taxRate);
26  $responseContent = [
27  'success' => true,
28  'error_message' => '',
29  'tax_calculation_rate_id' => $taxRate->getId(),
30  'code' => htmlspecialchars($taxRate->getCode()),
31  ];
32  } catch (\Magento\Framework\Exception\LocalizedException $e) {
33  $responseContent = [
34  'success' => false,
35  'error_message' => $e->getMessage(),
36  'tax_calculation_rate_id' => '',
37  'code' => '',
38  ];
39  } catch (\Exception $e) {
40  $responseContent = [
41  'success' => false,
42  'error_message' => __('We can\'t save this rate right now.'),
43  'tax_calculation_rate_id' => '',
44  'code' => '',
45  ];
46  }
47 
49  $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
50  $resultJson->setData($responseContent);
51  return $resultJson;
52  }
53 }
__()
Definition: __.php:13
$taxRate
Definition: tax_rule.php:12