Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExportTablerates.php
Go to the documentation of this file.
1 <?php
8 
12 
14 {
18  protected $_fileFactory;
19 
23  protected $_storeManager;
24 
32  public function __construct(
33  \Magento\Backend\App\Action\Context $context,
34  \Magento\Config\Model\Config\Structure $configStructure,
35  ConfigSectionChecker $sectionChecker,
36  \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
37  \Magento\Store\Model\StoreManagerInterface $storeManager
38  ) {
39  $this->_storeManager = $storeManager;
40  $this->_fileFactory = $fileFactory;
41  parent::__construct($context, $configStructure, $sectionChecker);
42  }
43 
49  public function execute()
50  {
51  $fileName = 'tablerates.csv';
53  $gridBlock = $this->_view->getLayout()->createBlock(
54  \Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid::class
55  );
56  $website = $this->_storeManager->getWebsite($this->getRequest()->getParam('website'));
57  if ($this->getRequest()->getParam('conditionName')) {
58  $conditionName = $this->getRequest()->getParam('conditionName');
59  } else {
60  $conditionName = $website->getConfig('carriers/tablerate/condition_name');
61  }
62  $gridBlock->setWebsiteId($website->getId())->setConditionName($conditionName);
63  $content = $gridBlock->getCsvFile();
64  return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR);
65  }
66 }
$storeManager
$fileName
Definition: translate.phtml:15
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Config\Model\Config\Structure $configStructure, ConfigSectionChecker $sectionChecker, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Store\Model\StoreManagerInterface $storeManager)