00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_ProductAlert 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * ProductAlert controller 00029 * 00030 * @category Mage 00031 * @package Mage_ProductAlert 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_ProductAlert_AddController extends Mage_Core_Controller_Front_Action 00035 { 00036 public function preDispatch() 00037 { 00038 parent::preDispatch(); 00039 00040 if (!Mage::getSingleton('customer/session')->authenticate($this)) { 00041 $this->setFlag('', 'no-dispatch', true); 00042 if(!Mage::getSingleton('customer/session')->getBeforeUrl()) { 00043 Mage::getSingleton('customer/session')->setBeforeUrl($this->_getRefererUrl()); 00044 } 00045 } 00046 } 00047 00048 public function testObserverAction() 00049 { 00050 $object = new Varien_Object(); 00051 $observer = Mage::getSingleton('productalert/observer'); 00052 $observer->process($object); 00053 } 00054 00055 public function priceAction() 00056 { 00057 $session = Mage::getSingleton('catalog/session'); 00058 $backUrl = $this->getRequest()->getParam(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED); 00059 $productId = (int) $this->getRequest()->getParam('product_id'); 00060 if (!$backUrl || !$productId) { 00061 $this->_redirect('/'); 00062 return ; 00063 } 00064 00065 $product = Mage::getModel('catalog/product')->load($productId); 00066 if (!$product->getId()) { 00067 /* @var $product Mage_Catalog_Model_Product */ 00068 $session->addError($this->__('Not enough parameters')); 00069 $this->_redirectUrl($backUrl); 00070 return ; 00071 } 00072 00073 try { 00074 $model = Mage::getModel('productalert/price') 00075 ->setCustomerId(Mage::getSingleton('customer/session')->getId()) 00076 ->setProductId($product->getId()) 00077 ->setPrice($product->getFinalPrice()) 00078 ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); 00079 $model->save(); 00080 $session->addSuccess($this->__('Alert subscription was saved successfully')); 00081 } 00082 catch (Exception $e) { 00083 $session->addException($e, $this->__('Please try again later')); 00084 } 00085 $this->_redirectReferer(); 00086 } 00087 00088 public function stockAction() 00089 { 00090 $session = Mage::getSingleton('catalog/session'); 00091 /* @var $session Mage_Catalog_Model_Session */ 00092 $backUrl = $this->getRequest()->getParam(Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED); 00093 $productId = (int) $this->getRequest()->getParam('product_id'); 00094 if (!$backUrl || !$productId) { 00095 $this->_redirect('/'); 00096 return ; 00097 } 00098 00099 if (!$product = Mage::getModel('catalog/product')->load($productId)) { 00100 /* @var $product Mage_Catalog_Model_Product */ 00101 $session->addError($this->__('Not enough parameters')); 00102 $this->_redirectUrl($backUrl); 00103 return ; 00104 } 00105 00106 try { 00107 $model = Mage::getModel('productalert/stock') 00108 ->setCustomerId(Mage::getSingleton('customer/session')->getId()) 00109 ->setProductId($product->getId()) 00110 ->setWebsiteId(Mage::app()->getStore()->getWebsiteId()); 00111 $model->save(); 00112 $session->addSuccess($this->__('Alert subscription was saved successfully')); 00113 } 00114 catch (Exception $e) { 00115 $session->addException($e, $this->__('Please try again later')); 00116 } 00117 $this->_redirectReferer(); 00118 } 00119 }