diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php index 2421267aa753d..11e87d4eac28c 100644 --- a/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php +++ b/app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php @@ -48,20 +48,17 @@ public function __construct( */ public function execute() { - $invoiceId = $this->getRequest()->getParam('invoice_id'); + $invoiceId = (int) $this->getRequest()->getParam('invoice_id'); if ($invoiceId) { $invoice = $this->_objectManager->create( \Magento\Sales\Api\InvoiceRepositoryInterface::class )->get($invoiceId); if ($invoice) { $pdf = $this->_objectManager->create(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf([$invoice]); - $date = $this->_objectManager->get( - \Magento\Framework\Stdlib\DateTime\DateTime::class - )->date('Y-m-d_H-i-s'); return $this->_fileFactory->create( - 'invoice' . $date . '.pdf', + "invoice_$invoiceId.pdf", $pdf->render(), - DirectoryList::VAR_DIR, + DirectoryList::PDF, 'application/pdf' ); } diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/PrintActionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/PrintActionTest.php index 29c0bd85c3619..8384992889d67 100644 --- a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/PrintActionTest.php +++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/Order/Invoice/PrintActionTest.php @@ -126,7 +126,6 @@ public function testExecute() ->willReturnSelf(); $pdfMock->expects($this->once()) ->method('render'); - $dateTimeMock = $this->createMock(\Magento\Framework\Stdlib\DateTime\DateTime::class); $invoiceRepository = $this->getMockBuilder(\Magento\Sales\Api\InvoiceRepositoryInterface::class) ->disableOriginalConstructor() @@ -143,10 +142,7 @@ public function testExecute() ->method('create') ->with(\Magento\Sales\Model\Order\Pdf\Invoice::class) ->willReturn($pdfMock); - $this->objectManagerMock->expects($this->at(2)) - ->method('get') - ->with(\Magento\Framework\Stdlib\DateTime\DateTime::class) - ->willReturn($dateTimeMock); + $this->assertNull($this->controller->execute()); } diff --git a/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php b/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php index 4b10a503f423c..5972bff639a06 100644 --- a/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php +++ b/lib/internal/Magento/Framework/App/Filesystem/DirectoryList.php @@ -135,6 +135,11 @@ class DirectoryList extends \Magento\Framework\Filesystem\DirectoryList */ const GENERATED_METADATA = 'metadata'; + /** + * Relative directory key for generated PDFs + */ + const PDF = 'pdf'; + /** * {@inheritdoc} */ @@ -164,6 +169,7 @@ public static function getDefaultConfig() self::GENERATED => [parent::PATH => 'generated'], self::GENERATED_CODE => [parent::PATH => Io::DEFAULT_DIRECTORY], self::GENERATED_METADATA => [parent::PATH => 'generated/metadata'], + self::PDF => [parent::PATH => 'var/pdf'], ]; return parent::getDefaultConfig() + $result; }