/** * Print credit memos for selected orders * * @param AbstractCollection $collection * @return ResponseInterface|ResultInterface */ protected function massAction(AbstractCollection $collection) { $creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]); if (!$creditmemoCollection->getSize()) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } return $this->fileFactory->create(sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfCreditmemo->getPdf($creditmemoCollection->getItems())->render(), DirectoryList::VAR_DIR, 'application/pdf'); }
/** * @covers \Magento\Sales\Controller\Adminhtml\Order\Creditmemo\PrintAction::executeInternal */ public function testExecute() { $creditmemoId = 2; $date = '2015-01-19_13-03-45'; $fileName = 'creditmemo2015-01-19_13-03-45.pdf'; $fileContents = 'pdf0123456789'; $this->prepareTestExecute($creditmemoId); $this->objectManagerMock->expects($this->any()) ->method('create') ->willReturnMap( [ ['Magento\Sales\Model\Order\Creditmemo', [], $this->creditmemoMock], ['Magento\Sales\Model\Order\Pdf\Creditmemo', [], $this->creditmemoPdfMock] ] ); $this->creditmemoRepositoryMock->expects($this->once()) ->method('get') ->with($creditmemoId) ->willReturn($this->creditmemoMock); $this->creditmemoPdfMock->expects($this->once()) ->method('getPdf') ->with([$this->creditmemoMock]) ->willReturn($this->pdfMock); $this->objectManagerMock->expects($this->once()) ->method('get') ->with('Magento\Framework\Stdlib\DateTime\DateTime') ->willReturn($this->dateTimeMock); $this->dateTimeMock->expects($this->once()) ->method('date') ->with('Y-m-d_H-i-s') ->willReturn($date); $this->pdfMock->expects($this->once()) ->method('render') ->willReturn($fileContents); $this->fileFactoryMock->expects($this->once()) ->method('create') ->with( $fileName, $fileContents, \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, 'application/pdf' ) ->willReturn($this->responseMock); $this->assertInstanceOf( 'Magento\Framework\App\ResponseInterface', $this->printAction->executeInternal() ); }
/** * @param AbstractCollection $collection * @return ResponseInterface * @throws \Exception * @throws \Zend_Pdf_Exception */ public function massAction(AbstractCollection $collection) { return $this->fileFactory->create(sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfCreditmemo->getPdf($collection)->render(), DirectoryList::VAR_DIR, 'application/pdf'); }
/** * Print all documents for selected orders * * @param AbstractCollection $collection * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function massAction(AbstractCollection $collection) { $orderIds = $collection->getAllIds(); $shipments = $this->shipmentCollectionFactory->create()->setOrderFilter(['in' => $orderIds]); $invoices = $this->invoiceCollectionFactory->create()->setOrderFilter(['in' => $orderIds]); $creditmemos = $this->creditmemoCollectionFactory->create()->setOrderFilter(['in' => $orderIds]); $documents = []; if ($invoices->getSize()) { $documents[] = $this->pdfInvoice->getPdf($invoices); } if ($shipments->getSize()) { $documents[] = $this->pdfShipment->getPdf($shipments); } if ($creditmemos->getSize()) { $documents[] = $this->pdfCreditmemo->getPdf($creditmemos); } if (empty($documents)) { $this->messageManager->addError(__('There are no printable documents related to selected orders.')); return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl()); } $pdf = array_shift($documents); foreach ($documents as $document) { $pdf->pages = array_merge($pdf->pages, $document->pages); } return $this->fileFactory->create(sprintf('docs%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf'); }