ExportCouponsCsv.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
  8. use Magento\Framework\App\Filesystem\DirectoryList;
  9. class ExportCouponsCsv extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
  10. {
  11. /**
  12. * Export coupon codes as CSV file
  13. *
  14. * @return \Magento\Framework\App\ResponseInterface|null
  15. */
  16. public function execute()
  17. {
  18. $this->_initRule();
  19. $rule = $this->_coreRegistry->registry(\Magento\SalesRule\Model\RegistryConstants::CURRENT_SALES_RULE);
  20. if ($rule->getId()) {
  21. $fileName = 'coupon_codes.csv';
  22. $content = $this->_view->getLayout()->createBlock(
  23. \Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons\Grid::class
  24. )->getCsvFile();
  25. return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR);
  26. } else {
  27. $this->_redirect('sales_rule/*/detail', ['_current' => true]);
  28. return;
  29. }
  30. }
  31. }