5
5
*/
6
6
namespace Magento \Sales \Controller \Adminhtml \Order ;
7
7
8
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
8
9
use Magento \Framework \App \ResponseInterface ;
9
10
use Magento \Framework \App \Filesystem \DirectoryList ;
10
11
use Magento \Framework \Model \ResourceModel \Db \Collection \AbstractCollection ;
21
22
use Magento \Sales \Model \ResourceModel \Order \Creditmemo \CollectionFactory as CreditmemoCollectionFactory ;
22
23
23
24
/**
24
- * Class Pdfdocs
25
+ * Export all docs in pdf
25
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
27
*/
27
- class Pdfdocs extends \Magento \Sales \Controller \Adminhtml \Order \AbstractMassAction
28
+ class Pdfdocs extends \Magento \Sales \Controller \Adminhtml \Order \AbstractMassAction implements HttpPostActionInterface
28
29
{
29
30
/**
30
31
* @var \Magento\Framework\App\Response\Http\FileFactory
@@ -124,13 +125,13 @@ protected function massAction(AbstractCollection $collection)
124
125
$ creditmemos = $ this ->creditmemoCollectionFactory ->create ()->setOrderFilter (['in ' => $ orderIds ]);
125
126
126
127
$ documents = [];
127
- if ($ invoices ->getSize ()) {
128
+ if ($ this -> _authorization -> isAllowed ( ' Magento_Sales::invoice ' ) && $ invoices ->getSize ()) {
128
129
$ documents [] = $ this ->pdfInvoice ->getPdf ($ invoices );
129
130
}
130
- if ($ shipments ->getSize ()) {
131
+ if ($ this -> _authorization -> isAllowed ( ' Magento_Sales::ship ' ) && $ shipments ->getSize ()) {
131
132
$ documents [] = $ this ->pdfShipment ->getPdf ($ shipments );
132
133
}
133
- if ($ creditmemos ->getSize ()) {
134
+ if ($ this -> _authorization -> isAllowed ( ' Magento_Sales::creditmemo ' ) && $ creditmemos ->getSize ()) {
134
135
$ documents [] = $ this ->pdfCreditmemo ->getPdf ($ creditmemos );
135
136
}
136
137
@@ -140,9 +141,13 @@ protected function massAction(AbstractCollection $collection)
140
141
}
141
142
142
143
$ pdf = array_shift ($ documents );
144
+ $ documentList = [];
143
145
foreach ($ documents as $ document ) {
144
- $ pdf -> pages = array_merge ( $ pdf -> pages , $ document ->pages ) ;
146
+ $ documentList [] = $ document ->pages ;
145
147
}
148
+
149
+ $ pdf ->pages = array_merge ($ pdf ->pages , array_merge (...$ documentList ));
150
+
146
151
$ fileContent = ['type ' => 'string ' , 'value ' => $ pdf ->render (), 'rm ' => true ];
147
152
148
153
return $ this ->fileFactory ->create (
0 commit comments