Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
18  public function execute()
19  {
20  $id = $this->getRequest()->getParam('id');
21  if ($id) {
22  try {
23  $model = $this->_objectManager->create(\Magento\SalesRule\Model\Rule::class);
24  $model->load($id);
25  $model->delete();
26  $this->messageManager->addSuccessMessage(__('You deleted the rule.'));
27  $this->_redirect('sales_rule/*/');
28  return;
29  } catch (\Magento\Framework\Exception\LocalizedException $e) {
30  $this->messageManager->addErrorMessage($e->getMessage());
31  } catch (\Exception $e) {
32  $this->messageManager->addErrorMessage(
33  __('We can\'t delete the rule right now. Please review the log and try again.')
34  );
35  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
36  $this->_redirect('sales_rule/*/edit', ['id' => $this->getRequest()->getParam('id')]);
37  return;
38  }
39  }
40  $this->messageManager->addErrorMessage(__('We can\'t find a rule to delete.'));
41  $this->_redirect('sales_rule/*/');
42  }
43 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13