fileFactory = $fileFactory; $this->dateTime = $dateTime; $this->pdfCreditmemo = $pdfCreditmemo; $this->collectionFactory = $collectionFactory; parent::__construct($context, $filter); } /** * Print credit memos for selected orders * * @param AbstractCollection $collection * @return ResponseInterface|ResultInterface * @throws \Exception */ protected function massAction(AbstractCollection $collection) { $creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); if (!$creditmemoCollection->getSize()) { $this->messageManager->addErrorMessage(__('There are no printable documents related to selected orders.')); return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } $pdf = $this->pdfCreditmemo->getPdf($creditmemoCollection->getItems()); $fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true]; return $this->fileFactory->create( sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $fileContent, DirectoryList::VAR_DIR, 'application/pdf' ); } }