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 
16 
17 class Delete extends Agreement implements HttpPostActionInterface
18 {
22  private $agreementRepository;
23 
29  public function __construct(
30  Context $context,
31  Registry $coreRegistry,
32  CheckoutAgreementsRepositoryInterface $agreementRepository = null
33  ) {
34  $this->agreementRepository = $agreementRepository ?:
35  ObjectManager::getInstance()->get(CheckoutAgreementsRepositoryInterface::class);
36  parent::__construct($context, $coreRegistry);
37  }
41  public function execute()
42  {
43  $id = (int)$this->getRequest()->getParam('id');
44  $agreement = $this->agreementRepository->get($id);
45  if (!$agreement->getAgreementId()) {
46  $this->messageManager->addError(__('This condition no longer exists.'));
47  $this->_redirect('checkout/*/');
48  return;
49  }
50 
51  try {
52  $this->agreementRepository->delete($agreement);
53  $this->messageManager->addSuccess(__('You deleted the condition.'));
54  $this->_redirect('checkout/*/');
55  return;
56  } catch (LocalizedException $e) {
57  $this->messageManager->addError($e->getMessage());
58  } catch (\Exception $e) {
59  $this->messageManager->addError(__('Something went wrong while deleting this condition.'));
60  }
61 
62  $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
63  }
64 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
__construct(Context $context, Registry $coreRegistry, CheckoutAgreementsRepositoryInterface $agreementRepository=null)
Definition: Delete.php:29