_processRateData($this->getRequest()->getPostValue()); /** @var \Magento\Tax\Api\Data\TaxRateInterface $taxRate */ $taxRate = $this->_taxRateConverter->populateTaxRateData($rateData); $this->_taxRateRepository->save($taxRate); $responseContent = [ 'success' => true, 'error_message' => '', 'tax_calculation_rate_id' => $taxRate->getId(), 'code' => htmlspecialchars($taxRate->getCode()), ]; } catch (\Magento\Framework\Exception\LocalizedException $e) { $responseContent = [ 'success' => false, 'error_message' => $e->getMessage(), 'tax_calculation_rate_id' => '', 'code' => '', ]; } catch (\Exception $e) { $responseContent = [ 'success' => false, 'error_message' => __('We can\'t save this rate right now.'), 'tax_calculation_rate_id' => '', 'code' => '', ]; } /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($responseContent); return $resultJson; } }