_storeManager = $storeManager; $this->_fileFactory = $fileFactory; parent::__construct($context, $configStructure, $sectionChecker); } /** * Export shipping table rates in csv format * * @return ResponseInterface */ public function execute() { $fileName = 'tablerates.csv'; /** @var $gridBlock \Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid */ $gridBlock = $this->_view->getLayout()->createBlock( \Magento\OfflineShipping\Block\Adminhtml\Carrier\Tablerate\Grid::class ); $website = $this->_storeManager->getWebsite($this->getRequest()->getParam('website')); if ($this->getRequest()->getParam('conditionName')) { $conditionName = $this->getRequest()->getParam('conditionName'); } else { $conditionName = $website->getConfig('carriers/tablerate/condition_name'); } $gridBlock->setWebsiteId($website->getId())->setConditionName($conditionName); $content = $gridBlock->getCsvFile(); return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR); } }