예제 #1
0
 /**
  * Unhold selected orders
  *
  * @param AbstractCollection $collection
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 protected function massAction(AbstractCollection $collection)
 {
     $countUnHoldOrder = 0;
     /** @var \Magento\Sales\Model\Order $order */
     foreach ($collection->getItems() as $order) {
         $order->load($order->getId());
         if (!$order->canUnhold()) {
             continue;
         }
         $order->unhold();
         $order->save();
         $countUnHoldOrder++;
     }
     $countNonUnHoldOrder = $collection->count() - $countUnHoldOrder;
     if ($countNonUnHoldOrder && $countUnHoldOrder) {
         $this->messageManager->addError(__('%1 order(s) were not released from on hold status.', $countNonUnHoldOrder));
     } elseif ($countNonUnHoldOrder) {
         $this->messageManager->addError(__('No order(s) were released from on hold status.'));
     }
     if ($countUnHoldOrder) {
         $this->messageManager->addSuccess(__('%1 order(s) have been released from on hold status.', $countUnHoldOrder));
     }
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath($this->getComponentRefererUrl());
     return $resultRedirect;
 }
예제 #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;
         }
         $this->orderManagement->hold($order->getEntityId());
         $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($this->getComponentRefererUrl());
     return $resultRedirect;
 }
예제 #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($this->getComponentRefererUrl());
     return $resultRedirect;
 }