*/ class Mage_ProductAlert_AddController extends Mage_Core_Controller_Front_Action { public function preDispatch() { parent::preDispatch(); if (!Mage::getSingleton('customer/session')->authenticate($this)) { $this->setFlag('', 'no-dispatch', true); if(!Mage::getSingleton('customer/session')->getBeforeUrl()) { Mage::getSingleton('customer/session')->setBeforeUrl($this->_getRefererUrl()); } } } public function testObserverAction() { $object = new Varien_Object(); $observer = Mage::getSingleton('productalert/observer'); $observer->process($object); } public function priceAction() { $session = Mage::getSingleton('catalog/session'); $backUrl = $this->getRequest()->getParam(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED); $productId = (int) $this->getRequest()->getParam('product_id'); if (!$backUrl || !$productId) { $this->_redirect('/'); return ; } $product = Mage::getModel('catalog/product')->load($productId); if (!$product->getId()) { /* @var $product Mage_Catalog_Model_Product */ $session->addError($this->__('Not enough parameters.')); if ($this->_isUrlInternal($backUrl)) { $this->_redirectUrl($backUrl); } else { $this->_redirect('/'); } return ; } try { $model = Mage::getModel('productalert/price') ->setCustomerId(Mage::getSingleton('customer/session')->getId()) ->setProductId($product->getId()) ->setPrice($product->getFinalPrice()) ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); $model->save(); $session->addSuccess($this->__('The alert subscription has been saved.')); } catch (Exception $e) { $session->addException($e, $this->__('Unable to update the alert subscription.')); } $this->_redirectReferer(); } public function stockAction() { $session = Mage::getSingleton('catalog/session'); /* @var $session Mage_Catalog_Model_Session */ $backUrl = $this->getRequest()->getParam(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED); $productId = (int) $this->getRequest()->getParam('product_id'); if (!$backUrl || !$productId) { $this->_redirect('/'); return ; } if (!$product = Mage::getModel('catalog/product')->load($productId)) { /* @var $product Mage_Catalog_Model_Product */ $session->addError($this->__('Not enough parameters.')); $this->_redirectUrl($backUrl); return ; } try { $model = Mage::getModel('productalert/stock') ->setCustomerId(Mage::getSingleton('customer/session')->getId()) ->setProductId($product->getId()) ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); $model->save(); $session->addSuccess($this->__('Alert subscription has been saved.')); } catch (Exception $e) { $session->addException($e, $this->__('Unable to update the alert subscription.')); } $this->_redirectReferer(); } }