ExportCouponsXml.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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 ExportCouponsXml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote
  10. {
  11. /**
  12. * Export coupon codes as excel xml 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.xml';
  22. $content = $this->_view->getLayout()->createBlock(
  23. \Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons\Grid::class
  24. )->getExcelFile(
  25. $fileName
  26. );
  27. return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR);
  28. } else {
  29. $this->_redirect('sales_rule/*/detail', ['_current' => true]);
  30. return;
  31. }
  32. }
  33. }