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_ProductAlert_UnsubscribeController extends Mage_Core_Controller_Front_Action
36: {
37: public function preDispatch()
38: {
39: parent::preDispatch();
40:
41: if (!Mage::getSingleton('customer/session')->authenticate($this)) {
42: $this->setFlag('', 'no-dispatch', true);
43: if(!Mage::getSingleton('customer/session')->getBeforeUrl()) {
44: Mage::getSingleton('customer/session')->setBeforeUrl($this->_getRefererUrl());
45: }
46: }
47: }
48:
49: public function priceAction()
50: {
51: $productId = (int) $this->getRequest()->getParam('product');
52:
53: if (!$productId) {
54: $this->_redirect('');
55: return;
56: }
57: $session = Mage::getSingleton('catalog/session');
58:
59:
60: $product = Mage::getModel('catalog/product')->load($productId);
61: if (!$product->getId() || !$product->isVisibleInCatalog()) {
62:
63: Mage::getSingleton('customer/session')->addError($this->__('The product is not found.'));
64: $this->_redirect('customer/account/');
65: return ;
66: }
67:
68: try {
69: $model = Mage::getModel('productalert/price')
70: ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
71: ->setProductId($product->getId())
72: ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
73: ->loadByParam();
74: if ($model->getId()) {
75: $model->delete();
76: }
77:
78: $session->addSuccess($this->__('The alert subscription has been deleted.'));
79: }
80: catch (Exception $e) {
81: $session->addException($e, $this->__('Unable to update the alert subscription.'));
82: }
83: $this->_redirectUrl($product->getProductUrl());
84: }
85:
86: public function priceAllAction()
87: {
88: $session = Mage::getSingleton('customer/session');
89:
90:
91: try {
92: Mage::getModel('productalert/price')->deleteCustomer(
93: $session->getCustomerId(),
94: Mage::app()->getStore()->getWebsiteId()
95: );
96: $session->addSuccess($this->__('You will no longer receive price alerts for this product.'));
97: }
98: catch (Exception $e) {
99: $session->addException($e, $this->__('Unable to update the alert subscription.'));
100: }
101: $this->_redirect('customer/account/');
102: }
103:
104: public function stockAction()
105: {
106: $productId = (int) $this->getRequest()->getParam('product');
107:
108: if (!$productId) {
109: $this->_redirect('');
110: return;
111: }
112:
113: $session = Mage::getSingleton('catalog/session');
114:
115: $product = Mage::getModel('catalog/product')->load($productId);
116:
117: if (!$product->getId() || !$product->isVisibleInCatalog()) {
118: Mage::getSingleton('customer/session')->addError($this->__('The product was not found.'));
119: $this->_redirect('customer/account/');
120: return ;
121: }
122:
123: try {
124: $model = Mage::getModel('productalert/stock')
125: ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
126: ->setProductId($product->getId())
127: ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
128: ->loadByParam();
129: if ($model->getId()) {
130: $model->delete();
131: }
132: $session->addSuccess($this->__('You will no longer receive stock alerts for this product.'));
133: }
134: catch (Exception $e) {
135: $session->addException($e, $this->__('Unable to update the alert subscription.'));
136: }
137: $this->_redirectUrl($product->getProductUrl());
138: }
139:
140: public function stockAllAction()
141: {
142: $session = Mage::getSingleton('customer/session');
143:
144:
145: try {
146: Mage::getModel('productalert/stock')->deleteCustomer(
147: $session->getCustomerId(),
148: Mage::app()->getStore()->getWebsiteId()
149: );
150: $session->addSuccess($this->__('You will no longer receive stock alerts.'));
151: }
152: catch (Exception $e) {
153: $session->addException($e, $this->__('Unable to update the alert subscription.'));
154: }
155: $this->_redirect('customer/account/');
156: }
157: }
158: