Exemplo n.º 1
0
 /**
  * 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');
 }
 /**
  * Batch print shipping labels for whole shipments.
  * Push pdf document with shipping labels to user browser
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|ResultInterface
  */
 protected function massAction(AbstractCollection $collection)
 {
     $labelsContent = [];
     $shipments = $this->shipmentCollectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]);
     if ($shipments->getSize()) {
         /** @var \Magento\Sales\Model\Order\Shipment $shipment */
         foreach ($shipments as $shipment) {
             $labelContent = $shipment->getShippingLabel();
             if ($labelContent) {
                 $labelsContent[] = $labelContent;
             }
         }
     }
     if (!empty($labelsContent)) {
         $outputPdf = $this->labelGenerator->combineLabelsPdf($labelsContent);
         return $this->fileFactory->create('ShippingLabels.pdf', $outputPdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     }
     $this->messageManager->addError(__('There are no shipping labels related to selected orders.'));
     return $this->resultRedirectFactory->create()->setPath('sales/order/');
 }
Exemplo n.º 3
0
 public function testGetAllIdsWithBind()
 {
     $this->_model->getSelect()->where('code = :code');
     $this->_model->addBindParam('code', 'admin');
     $this->assertEquals(['0'], $this->_model->getAllIds());
 }
Exemplo n.º 4
0
 /**
  * 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');
 }
Exemplo n.º 5
0
 /**
  * Retrieve all ids for collection
  *
  * @return array
  */
 public function getAllIds()
 {
     if ($this->_itemIds === null) {
         $this->_itemIds = parent::getAllIds();
     }
     return $this->_itemIds;
 }