Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Cancel.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 
12 {
18  const ADMIN_RESOURCE = 'Magento_Sales::cancel';
19 
25  public function execute()
26  {
27  $resultRedirect = $this->resultRedirectFactory->create();
28  if (!$this->isValidPostRequest()) {
29  $this->messageManager->addErrorMessage(__('You have not canceled the item.'));
30  return $resultRedirect->setPath('sales/*/');
31  }
32  $order = $this->_initOrder();
33  if ($order) {
34  try {
35  $this->orderManagement->cancel($order->getEntityId());
36  $this->messageManager->addSuccessMessage(__('You canceled the order.'));
37  } catch (\Magento\Framework\Exception\LocalizedException $e) {
38  $this->messageManager->addErrorMessage($e->getMessage());
39  } catch (\Exception $e) {
40  $this->messageManager->addErrorMessage(__('You have not canceled the item.'));
41  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
42  }
43  return $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
44  }
45  return $resultRedirect->setPath('sales/*/');
46  }
47 }
$order
Definition: order.php:55
__()
Definition: __.php:13