Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ImportPost.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
17  public function execute()
18  {
19  $importRatesFile = $this->getRequest()->getFiles('import_rates_file');
20  if ($this->getRequest()->isPost() && isset($importRatesFile['tmp_name'])) {
21  try {
23  $importHandler = $this->_objectManager->create(
24  \Magento\TaxImportExport\Model\Rate\CsvImportHandler::class
25  );
26  $importHandler->importFromCsvFile($importRatesFile);
27 
28  $this->messageManager->addSuccess(__('The tax rate has been imported.'));
29  } catch (\Magento\Framework\Exception\LocalizedException $e) {
30  $this->messageManager->addError($e->getMessage());
31  } catch (\Exception $e) {
32  $this->messageManager->addError(__('Invalid file upload attempt'));
33  }
34  } else {
35  $this->messageManager->addError(__('Invalid file upload attempt'));
36  }
38  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
39  $resultRedirect->setUrl($this->_redirect->getRedirectUrl());
40  return $resultRedirect;
41  }
42 
46  protected function _isAllowed()
47  {
48  return $this->_authorization->isAllowed(
49  'Magento_Tax::manage_tax'
50  ) || $this->_authorization->isAllowed(
51  'Magento_TaxImportExport::import_export'
52  );
53  }
54 }
Definition: ImportPost.php:10
__()
Definition: __.php:13
_isAllowed()
Definition: ImportPost.php:46