Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Export.php
Go to the documentation of this file.
1 <?php
7 
16 
18 {
22  protected $fileFactory;
23 
27  private $sessionManager;
28 
34  public function __construct(
35  Context $context,
37  \Magento\Framework\Session\SessionManagerInterface $sessionManager = null
38  ) {
39  $this->fileFactory = $fileFactory;
40  $this->sessionManager = $sessionManager ?: \Magento\Framework\App\ObjectManager::getInstance()
41  ->get(\Magento\Framework\Session\SessionManagerInterface::class);
42  parent::__construct($context);
43  }
44 
50  public function execute()
51  {
52  if ($this->getRequest()->getPost(ExportModel::FILTER_ELEMENT_GROUP)) {
53  try {
55  $model = $this->_objectManager->create(\Magento\ImportExport\Model\Export::class);
56  $model->setData($this->getRequest()->getParams());
57 
58  $this->sessionManager->writeClose();
59  return $this->fileFactory->create(
60  $model->getFileName(),
61  $model->export(),
62  DirectoryList::VAR_DIR,
63  $model->getContentType()
64  );
65  } catch (LocalizedException $e) {
66  $this->messageManager->addError($e->getMessage());
67  } catch (\Exception $e) {
68  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
69  $this->messageManager->addError(__('Please correct the data sent value.'));
70  }
71  } else {
72  $this->messageManager->addError(__('Please correct the data sent value.'));
73  }
75  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
76  $resultRedirect->setPath('adminhtml/*/index');
77  return $resultRedirect;
78  }
79 }
__()
Definition: __.php:13
__construct(Context $context, FileFactory $fileFactory, \Magento\Framework\Session\SessionManagerInterface $sessionManager=null)
Definition: Export.php:34