コード例 #1
1
 /**
  * Export shipment grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $resultPage = $this->resultPageFactory->create();
     $fileName = 'authors.csv';
     /** @var \Sample\News\Block\Adminhtml\Author\Grid $grid */
     $grid = $resultPage->getLayout()->getChildBlock('sample_news.author.grid', 'grid.export');
     return $this->fileFactory->create($fileName, $grid->getCsvFile(), DirectoryList::VAR_DIR);
 }
コード例 #2
0
ファイル: ExportCsv.php プロジェクト: aiesh/magento2
 /**
  * Export shipment grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout(false);
     $fileName = 'shipments.csv';
     $grid = $this->_view->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $grid->getCsvFile(), \Magento\Framework\App\Filesystem::VAR_DIR);
 }
コード例 #3
0
 /**
  * Export invoice grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $fileName = 'invoices.csv';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $this->resultLayoutFactory->create()->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
 }
コード例 #4
0
ファイル: PrintAction.php プロジェクト: nblair/magescotch
 /**
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
  */
 public function executeInternal()
 {
     /** @see \Magento\Sales\Controller\Adminhtml\Order\Invoice */
     $creditmemoId = $this->getRequest()->getParam('creditmemo_id');
     if ($creditmemoId) {
         $creditmemo = $this->creditmemoRepository->get($creditmemoId);
         if ($creditmemo) {
             $pdf = $this->_objectManager->create(
                 'Magento\Sales\Model\Order\Pdf\Creditmemo'
             )->getPdf(
                 [$creditmemo]
             );
             $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s');
             return $this->_fileFactory->create(
                 'creditmemo' . $date . '.pdf',
                 $pdf->render(),
                 DirectoryList::VAR_DIR,
                 'application/pdf'
             );
         }
     } else {
         $resultForward = $this->resultForwardFactory->create();
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
コード例 #5
0
ファイル: PrintPackage.php プロジェクト: nblair/magescotch
    /**
     * Create pdf document with information about packages
     *
     * @return ResponseInterface|void
     */
    public function executeInternal()
    {
        $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
        $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
        $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
        $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
        $shipment = $this->shipmentLoader->load();

        if ($shipment) {
            /** @var \Zend_Pdf $pdf */
            $pdf = $this->_objectManager->create('Magento\Shipping\Model\Order\Pdf\Packaging')->getPdf($shipment);
            return $this->_fileFactory->create(
                'packingslip' . $this->_objectManager->get(
                    'Magento\Framework\Stdlib\DateTime\DateTime'
                )->date(
                    'Y-m-d_H-i-s'
                ) . '.pdf',
                $pdf->render(),
                DirectoryList::VAR_DIR,
                'application/pdf'
            );
        } else {
            $this->_forward('noroute');
        }
    }
コード例 #6
0
 /**
  * Custom options download action
  *
  * @return \Magento\Framework\Controller\Result\Forward
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function execute()
 {
     $option = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->load($this->getRequest()->getParam('id'));
     /** @var \Magento\Framework\Controller\Result\Forward $resultForward */
     $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD);
     if (!$option->getId()) {
         $resultForward->forward('noroute');
         return $resultForward;
     }
     $optionId = null;
     if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
         $optionId = str_replace(\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode());
         if ((int) $optionId != $optionId) {
             $resultForward->forward('noroute');
             return $resultForward;
         }
     }
     $productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId);
     if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') {
         $resultForward->forward('noroute');
         return $resultForward;
     }
     try {
         $info = unserialize($option->getValue());
         $secretKey = $this->getRequest()->getParam('key');
         if ($secretKey == $info['secret_key']) {
             $this->_fileResponseFactory->create($info['title'], ['value' => $info['quote_path'], 'type' => 'filename'], DirectoryList::ROOT);
         }
     } catch (\Exception $e) {
         $resultForward->forward('noroute');
         return $resultForward;
     }
 }
コード例 #7
0
ファイル: ExportExcel.php プロジェクト: aiesh/magento2
 /**
  * Export invoice grid to Excel XML format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout();
     $fileName = 'invoices.xml';
     $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getExcelFile($fileName), \Magento\Framework\App\Filesystem::VAR_DIR);
 }
コード例 #8
0
 /**
  * Export search report to Excel XML format
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
     $content = $resultLayout->getLayout()->getChildBlock('adminhtml.report.search.grid', 'grid.export');
     return $this->fileFactory->create('search.xml', $content->getExcelFile(), DirectoryList::VAR_DIR);
 }
コード例 #9
0
ファイル: PrintAction.php プロジェクト: nblair/magescotch
 /**
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
  */
 public function executeInternal()
 {
     $shipmentId = $this->getRequest()->getParam('shipment_id');
     if ($shipmentId) {
         $shipment = $this->_objectManager->create('Magento\Sales\Model\Order\Shipment')->load($shipmentId);
         if ($shipment) {
             $pdf = $this->_objectManager->create(
                 'Magento\Sales\Model\Order\Pdf\Shipment'
             )->getPdf(
                 [$shipment]
             );
             $date = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\DateTime')->date('Y-m-d_H-i-s');
             return $this->_fileFactory->create(
                 'packingslip' . $date . '.pdf',
                 $pdf->render(),
                 DirectoryList::VAR_DIR,
                 'application/pdf'
             );
         }
     } else {
         /** @var \Magento\Backend\Model\View\Result\Forward $resultForward */
         $resultForward = $this->resultForwardFactory->create();
         return $resultForward->forward('noroute');
     }
 }
コード例 #10
0
 /**
  * Custom options download action
  *
  * @return void
  */
 public function execute()
 {
     $option = $this->_objectManager->create('Magento\\Wishlist\\Model\\Item\\Option')->load($this->getRequest()->getParam('id'));
     if (!$option->getId()) {
         return $this->_forward('noroute');
     }
     $optionId = null;
     if (strpos($option->getCode(), \Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX) === 0) {
         $optionId = str_replace(\Magento\Catalog\Model\Product\Type\AbstractType::OPTION_PREFIX, '', $option->getCode());
         if ((int) $optionId != $optionId) {
             return $this->_forward('noroute');
         }
     }
     $productOption = $this->_objectManager->create('Magento\\Catalog\\Model\\Product\\Option')->load($optionId);
     if (!$productOption || !$productOption->getId() || $productOption->getProductId() != $option->getProductId() || $productOption->getType() != 'file') {
         return $this->_forward('noroute');
     }
     try {
         $info = unserialize($option->getValue());
         $filePath = $this->_objectManager->get('Magento\\Framework\\App\\Filesystem')->getPath(\Magento\Framework\App\Filesystem::ROOT_DIR) . $info['quote_path'];
         $secretKey = $this->getRequest()->getParam('key');
         if ($secretKey == $info['secret_key']) {
             $this->_fileResponseFactory->create($info['title'], array('value' => $filePath, 'type' => 'filename'), \Magento\Framework\App\Filesystem::ROOT_DIR);
         }
     } catch (\Exception $e) {
         $this->_forward('noroute');
     }
     exit(0);
 }
コード例 #11
0
ファイル: ExportExcel.php プロジェクト: aiesh/magento2
 /**
  * Export credit memo grid to Excel XML format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout(false);
     $fileName = 'creditmemos.xml';
     $grid = $this->_view->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $grid->getExcelFile($fileName), \Magento\Framework\App\Filesystem::VAR_DIR);
 }
コード例 #12
0
ファイル: Pdfinvoices.php プロジェクト: nja78/magento2
 /**
  * Print invoices for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     $flag = false;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $invoices = $order->getInvoiceCollection();
         if ($invoices->getSize() > 0) {
             $flag = true;
             if (!isset($pdf)) {
                 $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
             } else {
                 $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf($invoices);
                 $pdf->pages = array_merge($pdf->pages, $pages->pages);
             }
         }
     }
     if ($flag) {
         $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
         return $this->fileFactory->create('invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     } else {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         $resultRedirect->setPath('sales/*/');
         return $resultRedirect;
     }
 }
コード例 #13
0
 /**
  * Print label for one specific shipment
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     try {
         $this->shipmentLoader->setOrderId($this->getRequest()->getParam('order_id'));
         $this->shipmentLoader->setShipmentId($this->getRequest()->getParam('shipment_id'));
         $this->shipmentLoader->setShipment($this->getRequest()->getParam('shipment'));
         $this->shipmentLoader->setTracking($this->getRequest()->getParam('tracking'));
         $shipment = $this->shipmentLoader->load();
         $labelContent = $shipment->getShippingLabel();
         if ($labelContent) {
             $pdfContent = null;
             if (stripos($labelContent, '%PDF-') !== false) {
                 $pdfContent = $labelContent;
             } else {
                 $pdf = new \Zend_Pdf();
                 $page = $this->labelGenerator->createPdfPageFromImageString($labelContent);
                 if (!$page) {
                     $this->messageManager->addError(__('We don\'t recognize or support the file extension in this shipment: %1.', $shipment->getIncrementId()));
                 }
                 $pdf->pages[] = $page;
                 $pdfContent = $pdf->render();
             }
             return $this->_fileFactory->create('ShippingLabel(' . $shipment->getIncrementId() . ').pdf', $pdfContent, DirectoryList::VAR_DIR, 'application/pdf');
         }
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
         $this->messageManager->addError(__('An error occurred while creating shipping label.'));
     }
     $this->_redirect('adminhtml/order_shipment/view', ['shipment_id' => $this->getRequest()->getParam('shipment_id')]);
 }
コード例 #14
0
 public function testCreate()
 {
     $authStorageMock = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', array('isFirstPageAfterLogin', 'processLogout', 'processLogin'), array(), '', false);
     $this->_authMock->expects($this->once())->method('getAuthStorage')->will($this->returnValue($authStorageMock));
     $authStorageMock->expects($this->once())->method('isFirstPageAfterLogin')->will($this->returnValue(true));
     $this->_sessionMock->expects($this->once())->method('setIsUrlNotice');
     $this->_model->create('fileName', null);
 }
コード例 #15
0
 /**
  * Export customer grid to CSV format
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout();
     $fileName = 'customers.csv';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $this->_view->getLayout()->getChildBlock('admin.block.customer.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
 }
コード例 #16
0
 /**
  * Export shipment grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $fileName = 'shipments.csv';
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultLayoutFactory->create();
     $grid = $resultLayout->getLayout()->getChildBlock('sales.shipment.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $grid->getCsvFile(), DirectoryList::VAR_DIR);
 }
コード例 #17
0
ファイル: ExportCsv.php プロジェクト: aiesh/magento2
 /**
  * Export invoice grid to CSV format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout();
     $fileName = 'invoices.csv';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $this->_view->getLayout()->getChildBlock('sales.invoice.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), \Magento\Framework\App\Filesystem::VAR_DIR);
 }
コード例 #18
0
 /**
  * Export credit memo grid to Excel XML format
  *
  * @return ResponseInterface
  */
 public function execute()
 {
     $fileName = 'creditmemos.xml';
     $resultLayout = $this->resultLayoutFactory->create();
     $grid = $resultLayout->getLayout()->getChildBlock('sales.creditmemo.grid', 'grid.export');
     $excelFile = $grid->getExcelFile($fileName);
     return $this->_fileFactory->create($fileName, $excelFile, DirectoryList::VAR_DIR);
 }
コード例 #19
0
 /**
  * Print credit memos for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|ResultInterface
  */
 protected function massAction(AbstractCollection $collection)
 {
     $creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]);
     if (!$creditmemoCollection->getSize()) {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
     }
     return $this->fileFactory->create(sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfCreditmemo->getPdf($creditmemoCollection->getItems())->render(), DirectoryList::VAR_DIR, 'application/pdf');
 }
コード例 #20
0
ファイル: ExportXml.php プロジェクト: aiesh/magento2
 /**
  * Export customer grid to XML format
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     $this->_view->loadLayout();
     $fileName = 'customers.xml';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $this->_view->getLayout()->getChildBlock('admin.block.customer.grid', 'grid.export');
     $content = $exportBlock->getExcelFile($fileName);
     return $this->_fileFactory->create($fileName, $content, \Magento\Framework\App\Filesystem::VAR_DIR);
 }
コード例 #21
0
 /**
  * Export cannedresponse grid to CSV format
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function execute()
 {
     /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $fileName = 'weblog.csv';
     /** @var \Magento\Backend\Block\Widget\Grid\ExportInterface $exportBlock  */
     $exportBlock = $resultPage->getLayout()->getChildBlock('weblog.grid', 'grid.export');
     return $this->_fileFactory->create($fileName, $exportBlock->getCsvFile(), DirectoryList::VAR_DIR);
 }
コード例 #22
0
 /**
  * Create pdf document with information about packages
  *
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $shipment = $this->shipmentLoader->load($this->_request);
     if ($shipment) {
         $pdf = $this->_objectManager->create('Magento\\Shipping\\Model\\Order\\Pdf\\Packaging')->getPdf($shipment);
         return $this->_fileFactory->create('packingslip' . $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s') . '.pdf', $pdf->render(), \Magento\Framework\App\Filesystem::VAR_DIR, 'application/pdf');
     } else {
         $this->_forward('noroute');
     }
 }
コード例 #23
0
 public function testExportVarnishConfigAction()
 {
     $fileContent = 'some conetnt';
     $filename = 'varnish.vcl';
     $responseMock = $this->getMockBuilder('Magento\\Framework\\App\\ResponseInterface')->disableOriginalConstructor()->getMock();
     $this->configMock->expects($this->once())->method('getVclFile')->will($this->returnValue($fileContent));
     $this->fileFactoryMock->expects($this->once())->method('create')->with($this->equalTo($filename), $this->equalTo($fileContent), $this->equalTo(DirectoryList::VAR_DIR))->will($this->returnValue($responseMock));
     $result = $this->action->executeInternal();
     $this->assertInstanceOf('Magento\\Framework\\App\\ResponseInterface', $result);
 }
コード例 #24
0
ファイル: Pdfshipments.php プロジェクト: nja78/magento2
 /**
  * @param AbstractCollection $collection
  * @return $this|ResponseInterface
  * @throws \Exception
  */
 public function massAction(AbstractCollection $collection)
 {
     if (!isset($pdf)) {
         $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Shipment')->getPdf($collection);
     } else {
         $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Shipment')->getPdf($collection);
         $pdf->pages = array_merge($pdf->pages, $pages->pages);
     }
     $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
     return $this->_fileFactory->create('packingslip' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
 }
コード例 #25
0
ファイル: Download.php プロジェクト: shabbirvividads/magento2
 /**
  * Custom options downloader
  *
  * @param array $info
  * @return void
  * @throws \Exception
  */
 public function downloadFile($info)
 {
     $relativePath = $info['order_path'];
     if ($this->_isCanProcessed($relativePath)) {
         //try get file from quote
         $relativePath = $info['quote_path'];
         if ($this->_isCanProcessed($relativePath)) {
             throw new \Exception();
         }
     }
     $this->_fileFactory->create($info['title'], ['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'], DirectoryList::ROOT);
 }
コード例 #26
0
ファイル: Download.php プロジェクト: aiesh/magento2
 /**
  * Custom options downloader
  *
  * @param array $info
  * @return void
  * @throws \Exception
  */
 public function downloadFile($info)
 {
     $relativePath = $info['order_path'];
     if ($this->_isCanProcessed($relativePath)) {
         //try get file from quote
         $relativePath = $info['quote_path'];
         if ($this->_isCanProcessed($relativePath)) {
             throw new \Exception();
         }
     }
     $this->_fileFactory->create($info['title'], array('value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'), \Magento\Framework\App\Filesystem::ROOT_DIR);
 }
コード例 #27
0
 /**
  * Custom options downloader
  *
  * @param array $info
  * @return void
  * @throws \Exception
  */
 public function downloadFile($info)
 {
     $relativePath = $info['order_path'];
     if (!$this->_isCanProcessed($relativePath)) {
         //try get file from quote
         $relativePath = $info['quote_path'];
         if (!$this->_isCanProcessed($relativePath)) {
             throw new LocalizedException(__('Path "%1" is not part of allowed directory "%2"', $relativePath, $this->rootDirBasePath));
         }
     }
     $this->_fileFactory->create($info['title'], ['value' => $this->_rootDir->getRelativePath($relativePath), 'type' => 'filename'], $this->rootDirBasePath);
 }
コード例 #28
0
 /**
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $invoiceId = $this->getRequest()->getParam('invoice_id');
     if ($invoiceId) {
         $invoice = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Invoice')->load($invoiceId);
         if ($invoice) {
             $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Invoice')->getPdf([$invoice]);
             $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
             return $this->_fileFactory->create('invoice' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
         }
     } else {
         return $this->resultForwardFactory->create()->forward('noroute');
     }
 }
コード例 #29
0
ファイル: PrintAction.php プロジェクト: aiesh/magento2
 /**
  * @return ResponseInterface|void
  */
 public function execute()
 {
     $shipmentId = $this->getRequest()->getParam('shipment_id');
     if ($shipmentId) {
         $shipment = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Shipment')->load($shipmentId);
         if ($shipment) {
             $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Shipment')->getPdf(array($shipment));
             $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
             return $this->_fileFactory->create('packingslip' . $date . '.pdf', $pdf->render(), \Magento\Framework\App\Filesystem::VAR_DIR, 'application/pdf');
         }
     } else {
         $this->_forward('noroute');
     }
 }
コード例 #30
0
 /**
  * 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');
     $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, \Magento\Framework\App\Filesystem::VAR_DIR);
 }