Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Save.php
Go to the documentation of this file.
1 <?php
8 
11 
13 {
19  public function execute()
20  {
22  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
23  $ratePost = $this->getRequest()->getPostValue();
24  if ($ratePost) {
25  $rateId = $this->getRequest()->getParam('tax_calculation_rate_id');
26  if ($rateId) {
27  try {
28  $this->_taxRateRepository->get($rateId);
29  } catch (NoSuchEntityException $e) {
30  unset($ratePost['tax_calculation_rate_id']);
31  }
32  }
33 
34  try {
35  $taxData = $this->_taxRateConverter->populateTaxRateData($ratePost);
36  $this->_taxRateRepository->save($taxData);
37 
38  $this->messageManager->addSuccess(__('You saved the tax rate.'));
39  return $resultRedirect->setPath('*/*/');
40  } catch (\Magento\Framework\Exception\LocalizedException $e) {
41  $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setFormData($ratePost);
42  $this->messageManager->addError($e->getMessage());
43  } catch (\Exception $e) {
44  $this->messageManager->addError($e->getMessage());
45  }
46  return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
47  }
48  return $resultRedirect->setPath('tax/rate');
49  }
50 }
__()
Definition: __.php:13