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 
10 
12 {
16  public function execute()
17  {
19  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
20  $postData = $this->getRequest()->getPostValue();
21  if ($postData) {
22  $postData['calculate_subtotal'] = $this->getRequest()->getParam('calculate_subtotal', 0);
24  try {
25  $taxRule = $this->ruleService->save($taxRule);
26 
27  $this->messageManager->addSuccess(__('You saved the tax rule.'));
28 
29  if ($this->getRequest()->getParam('back')) {
30  return $resultRedirect->setPath('tax/*/edit', ['rule' => $taxRule->getId()]);
31  }
32  return $resultRedirect->setPath('tax/*/');
33  } catch (\Magento\Framework\Exception\LocalizedException $e) {
34  $this->messageManager->addError($e->getMessage());
35  } catch (\Exception $e) {
36  $this->messageManager->addError(__('We can\'t save this tax rule right now.'));
37  }
38 
39  $this->_objectManager->get(\Magento\Backend\Model\Session::class)->setRuleData($postData);
40  return $resultRedirect->setUrl($this->_redirect->getRedirectUrl($this->getUrl('*')));
41  }
42  return $resultRedirect->setPath('tax/rule');
43  }
44 }
__()
Definition: __.php:13
$taxRule
Definition: tax_rule.php:35