Public Member Functions | |
newAction () | |
confirmAction () | |
unsubscribeAction () |
Definition at line 34 of file SubscriberController.php.
confirmAction | ( | ) |
Subscription confirm action
Definition at line 71 of file SubscriberController.php.
00072 { 00073 $id = (int) $this->getRequest()->getParam('id'); 00074 $code = (string) $this->getRequest()->getParam('code'); 00075 00076 if ($id && $code) { 00077 $subscriber = Mage::getModel('newsletter/subscriber')->load($id); 00078 $session = Mage::getSingleton('core/session'); 00079 00080 if($subscriber->getId() && $subscriber->getCode()) { 00081 if($subscriber->confirm($code)) { 00082 $session->addSuccess($this->__('Your subscription was successfully confirmed')); 00083 } else { 00084 $session->addError($this->__('Invalid subscription confirmation code')); 00085 } 00086 } else { 00087 $session->addError($this->__('Invalid subscription ID')); 00088 } 00089 } 00090 00091 $this->_redirectUrl(Mage::getBaseUrl()); 00092 }
newAction | ( | ) |
New subscription action
Definition at line 39 of file SubscriberController.php.
00040 { 00041 if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) { 00042 $session = Mage::getSingleton('core/session'); 00043 $email = (string) $this->getRequest()->getPost('email'); 00044 00045 try { 00046 if (!Zend_Validate::is($email, 'EmailAddress')) { 00047 Mage::throwException($this->__('Please enter a valid email address')); 00048 } 00049 00050 $status = Mage::getModel('newsletter/subscriber')->subscribe($email); 00051 if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) { 00052 $session->addSuccess($this->__('Confirmation request has been sent')); 00053 } 00054 else { 00055 $session->addSuccess($this->__('Thank you for your subscription')); 00056 } 00057 } 00058 catch (Mage_Core_Exception $e) { 00059 $session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage())); 00060 } 00061 catch (Exception $e) { 00062 $session->addException($e, $this->__('There was a problem with the subscription')); 00063 } 00064 } 00065 $this->_redirectReferer(); 00066 }
unsubscribeAction | ( | ) |
Unsubscribe newsletter
Definition at line 97 of file SubscriberController.php.
00098 { 00099 $id = (int) $this->getRequest()->getParam('id'); 00100 $code = (string) $this->getRequest()->getParam('code'); 00101 00102 if ($id && $code) { 00103 $session = Mage::getSingleton('core/session'); 00104 try { 00105 Mage::getModel('newsletter/subscriber')->load($id) 00106 ->setCheckCode($code) 00107 ->unsubscribe(); 00108 $session->addSuccess($this->__('You have been successfully unsubscribed.')); 00109 } 00110 catch (Mage_Core_Exception $e) { 00111 $session->addException($e, $e->getMessage()); 00112 } 00113 catch (Exception $e) { 00114 $session->addException($e, $this->__('There was a problem with the un-subscription.')); 00115 } 00116 } 00117 $this->_redirectReferer(); 00118 }