Esempio n. 1
0
 /**
  * Print credit memos for selected orders
  *
  * @param AbstractCollection $collection
  * @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     $flag = false;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $creditmemos = $order->getCreditmemosCollection();
         if ($creditmemos->getSize()) {
             $flag = true;
             if (!isset($pdf)) {
                 $pdf = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Creditmemo')->getPdf($creditmemos);
             } else {
                 $pages = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Pdf\\Creditmemo')->getPdf($creditmemos);
                 $pdf->pages = array_merge($pdf->pages, $pages->pages);
             }
         }
     }
     if ($flag) {
         $date = $this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\DateTime')->date('Y-m-d_H-i-s');
         return $this->_fileFactory->create('creditmemo' . $date . '.pdf', $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
     } else {
         $this->messageManager->addError(__('There are no printable documents related to selected orders.'));
         $resultRedirect->setPath('sales/*/');
         return $resultRedirect;
     }
 }
Esempio n. 2
0
 /**
  * Hold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countHoldOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canHold()) {
             continue;
         }
         $order->hold();
         $order->save();
         $countHoldOrder++;
     }
     $countNonHoldOrder = $collection->count() - $countHoldOrder;
     if ($countNonHoldOrder && $countHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not put on hold.', $countNonHoldOrder));
     } elseif ($countNonHoldOrder) {
         $this->messageManager->addError(__('No order(s) were put on hold.'));
     }
     if ($countHoldOrder) {
         $this->messageManager->addSuccess(__('You have put %1 order(s) on hold.', $countHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('sales/*/');
     return $resultRedirect;
 }
Esempio n. 3
0
 /**
  * Cancel selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countCancelOrder = 0;
     foreach ($collection->getItems() as $order) {
         if (!$order->canCancel()) {
             continue;
         }
         $order->cancel();
         $order->save();
         $countCancelOrder++;
     }
     $countNonCancelOrder = $collection->count() - $countCancelOrder;
     if ($countNonCancelOrder && $countCancelOrder) {
         $this->messageManager->addError(__('%1 order(s) cannot be canceled.', $countNonCancelOrder));
     } elseif ($countNonCancelOrder) {
         $this->messageManager->addError(__('You cannot cancel the order(s).'));
     }
     if ($countCancelOrder) {
         $this->messageManager->addSuccess(__('We canceled %1 order(s).', $countCancelOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('sales/*/');
     return $resultRedirect;
 }
Esempio n. 4
0
 /**
  * Filter collection by removing not available product types
  *
  * @param \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection $collection
  * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection
  */
 public function applySalableProductTypesFilter($collection)
 {
     $productTypes = $this->_salesConfig->getAvailableProductTypes();
     foreach ($collection->getItems() as $key => $item) {
         if ($item instanceof \Magento\Catalog\Model\Product) {
             $type = $item->getTypeId();
         } elseif ($item instanceof \Magento\Sales\Model\Order\Item) {
             $type = $item->getProductType();
         } elseif ($item instanceof \Magento\Quote\Model\Quote\Item) {
             $type = $item->getProductType();
         } else {
             $type = '';
         }
         if (!in_array($type, $productTypes)) {
             $collection->removeItemByKey($key);
         }
     }
     return $collection;
 }