Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Unsubscribe.php
Go to the documentation of this file.
1 <?php
8 
10 {
15  public function execute()
16  {
17  $id = (int)$this->getRequest()->getParam('id');
18  $code = (string)$this->getRequest()->getParam('code');
19 
20  if ($id && $code) {
21  try {
22  $this->_subscriberFactory->create()->load($id)->setCheckCode($code)->unsubscribe();
23  $this->messageManager->addSuccess(__('You unsubscribed.'));
24  } catch (\Magento\Framework\Exception\LocalizedException $e) {
25  $this->messageManager->addException($e, $e->getMessage());
26  } catch (\Exception $e) {
27  $this->messageManager->addException($e, __('Something went wrong while unsubscribing you.'));
28  }
29  }
30  $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
31  }
32 }
_redirect($path, $arguments=[])
Definition: Action.php:167
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
$code
Definition: info.phtml:12