1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Newsletter_ManageController extends Mage_Core_Controller_Front_Action
36: {
37: 38: 39: 40: 41:
42: public function preDispatch()
43: {
44: parent::preDispatch();
45: if (!Mage::getSingleton('customer/session')->authenticate($this)) {
46: $this->setFlag('', 'no-dispatch', true);
47: }
48: }
49:
50: public function indexAction()
51: {
52: $this->loadLayout();
53: $this->_initLayoutMessages('customer/session');
54: $this->_initLayoutMessages('catalog/session');
55:
56: if ($block = $this->getLayout()->getBlock('customer_newsletter')) {
57: $block->setRefererUrl($this->_getRefererUrl());
58: }
59: $this->getLayout()->getBlock('head')->setTitle($this->__('Newsletter Subscription'));
60: $this->renderLayout();
61: }
62:
63: public function saveAction()
64: {
65: if (!$this->_validateFormKey()) {
66: return $this->_redirect('customer/account/');
67: }
68: try {
69: Mage::getSingleton('customer/session')->getCustomer()
70: ->setStoreId(Mage::app()->getStore()->getId())
71: ->setIsSubscribed((boolean)$this->getRequest()->getParam('is_subscribed', false))
72: ->save();
73: if ((boolean)$this->getRequest()->getParam('is_subscribed', false)) {
74: Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been saved.'));
75: } else {
76: Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been removed.'));
77: }
78: }
79: catch (Exception $e) {
80: Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription.'));
81: }
82: $this->_redirect('customer/account/');
83: }
84: }
85: