_initRule(); $rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE); if ($rule->getId()) { $fileName = 'coupon_codes.xml'; $content = $this->_view->getLayout()->createBlock( \Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons\Grid::class )->getExcelFile( $fileName ); return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR); } else { $this->_redirect('sales_rule/*/detail', ['_current' => true]); return; } } }