00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_ProductAlert_UnsubscribeController extends Mage_Core_Controller_Front_Action
00036 {
00037 public function preDispatch()
00038 {
00039 parent::preDispatch();
00040
00041 if (!Mage::getSingleton('customer/session')->authenticate($this)) {
00042 $this->setFlag('', 'no-dispatch', true);
00043 if(!Mage::getSingleton('customer/session')->getBeforeUrl()) {
00044 Mage::getSingleton('customer/session')->setBeforeUrl($this->_getRefererUrl());
00045 }
00046 }
00047 }
00048
00049 public function priceAction()
00050 {
00051 $productId = (int) $this->getRequest()->getParam('product');
00052
00053 if (!$productId) {
00054 $this->_redirect('');
00055 return;
00056 }
00057 $session = Mage::getSingleton('catalog/session');
00058
00059
00060 $product = Mage::getModel('catalog/product')->load($productId);
00061 if (!$product->getId() || !$product->isVisibleInCatalog()) {
00062
00063 Mage::getSingleton('customer/session')->addError($this->__('Product not found'));
00064 $this->_redirect('customer/account/');
00065 return ;
00066 }
00067
00068 try {
00069 $model = Mage::getModel('productalert/price')
00070 ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
00071 ->setProductId($product->getId())
00072 ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
00073 ->loadByParam();
00074 if ($model->getId()) {
00075 $model->delete();
00076 }
00077
00078 $session->addSuccess($this->__('Alert subscription was deleted successfully'));
00079 }
00080 catch (Exception $e) {
00081 $session->addException($e, $this->__('Please try again later'));
00082 }
00083 $this->_redirectUrl($product->getProductUrl());
00084 }
00085
00086 public function priceAllAction()
00087 {
00088 $session = Mage::getSingleton('customer/session');
00089
00090
00091 try {
00092 Mage::getModel('productalert/price')->deleteCustomer(
00093 $session->getCustomerId(),
00094 Mage::app()->getStore()->getWebsiteId()
00095 );
00096 $session->addSuccess($this->__('You will no longer receive price alerts for this product'));
00097 }
00098 catch (Exception $e) {
00099 $session->addException($e, $this->__('Please try again later'));
00100 }
00101 $this->_redirect('customer/account/');
00102 }
00103
00104 public function stockAction()
00105 {
00106 $productId = (int) $this->getRequest()->getParam('product');
00107
00108 if (!$productId) {
00109 $this->_redirect('');
00110 return;
00111 }
00112
00113 $session = Mage::getSingleton('catalog/session');
00114
00115 $product = Mage::getModel('catalog/product')->load($productId);
00116
00117 if (!$product->getId() || !$product->isVisibleInCatalog()) {
00118 Mage::getSingleton('customer/session')->addError($this->__('Product not found'));
00119 $this->_redirect('customer/account/');
00120 return ;
00121 }
00122
00123 try {
00124 $model = Mage::getModel('productalert/stock')
00125 ->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId())
00126 ->setProductId($product->getId())
00127 ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
00128 ->loadByParam();
00129 if ($model->getId()) {
00130 $model->delete();
00131 }
00132 $session->addSuccess($this->__('You will no longer receive stock alerts for this product'));
00133 }
00134 catch (Exception $e) {
00135 $session->addException($e, $this->__('Please try again later'));
00136 }
00137 $this->_redirectUrl($product->getProductUrl());
00138 }
00139
00140 public function stockAllAction()
00141 {
00142 $session = Mage::getSingleton('customer/session');
00143
00144
00145 try {
00146 Mage::getModel('productalert/stock')->deleteCustomer(
00147 $session->getCustomerId(),
00148 Mage::app()->getStore()->getWebsiteId()
00149 );
00150 $session->addSuccess($this->__('You will no longer receive stock alerts'));
00151 }
00152 catch (Exception $e) {
00153 $session->addException($e, $this->__('Please try again later'));
00154 }
00155 $this->_redirect('customer/account/');
00156 }
00157 }