PdfDocumentsMassAction.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Controller\Adminhtml\Order;
  7. use Magento\Framework\Controller\ResultFactory;
  8. abstract class PdfDocumentsMassAction extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
  9. {
  10. /**
  11. * @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
  12. */
  13. protected $orderCollectionFactory;
  14. /**
  15. * Execute action
  16. *
  17. * @return \Magento\Backend\Model\View\Result\Redirect
  18. * @throws \Magento\Framework\Exception\LocalizedException|\Exception
  19. */
  20. public function execute()
  21. {
  22. try {
  23. $collection = $this->filter->getCollection($this->getOrderCollection()->create());
  24. return $this->massAction($collection);
  25. } catch (\Exception $e) {
  26. $this->messageManager->addErrorMessage($e->getMessage());
  27. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  28. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  29. return $resultRedirect->setPath($this->redirectUrl);
  30. }
  31. }
  32. /**
  33. * Get Order Collection Factory
  34. *
  35. * @return \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
  36. * @deprecated 100.1.3
  37. */
  38. private function getOrderCollection()
  39. {
  40. if ($this->orderCollectionFactory === null) {
  41. $this->orderCollectionFactory = \Magento\Framework\App\ObjectManager::getInstance()->get(
  42. \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class
  43. );
  44. }
  45. return $this->orderCollectionFactory;
  46. }
  47. }