Delete.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
  8. use Magento\Framework\App\Action\HttpPostActionInterface;
  9. class Delete extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpPostActionInterface
  10. {
  11. /**
  12. * Delete promo quote action
  13. *
  14. * @return void
  15. */
  16. public function execute()
  17. {
  18. $id = $this->getRequest()->getParam('id');
  19. if ($id) {
  20. try {
  21. $model = $this->_objectManager->create(\Magento\SalesRule\Model\Rule::class);
  22. $model->load($id);
  23. $model->delete();
  24. $this->messageManager->addSuccessMessage(__('You deleted the rule.'));
  25. $this->_redirect('sales_rule/*/');
  26. return;
  27. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  28. $this->messageManager->addErrorMessage($e->getMessage());
  29. } catch (\Exception $e) {
  30. $this->messageManager->addErrorMessage(
  31. __('We can\'t delete the rule right now. Please review the log and try again.')
  32. );
  33. $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
  34. $this->_redirect('sales_rule/*/edit', ['id' => $this->getRequest()->getParam('id')]);
  35. return;
  36. }
  37. }
  38. $this->messageManager->addErrorMessage(__('We can\'t find a rule to delete.'));
  39. $this->_redirect('sales_rule/*/');
  40. }
  41. }