pricealarm.php

Go to the documentation of this file.
00001 <?php
00002 
00011 class Pricealarm extends oxUBase
00012 {
00013 
00019     protected $_sThisTemplate = 'pricealarm.tpl';
00020 
00026     protected $_oArticle = null;
00027 
00033     protected $_sBidPrice = null;
00034 
00040     protected $_iPriceAlarmStatus = null;
00041 
00051     public function addme()
00052     {
00053         $myConfig = $this->getConfig();
00054         $myUtils = oxRegistry::getUtils();
00055 
00056         //control captcha
00057         $sMac = oxRegistry::getConfig()->getRequestParameter('c_mac');
00058         $sMacHash = oxRegistry::getConfig()->getRequestParameter('c_mach');
00059         $oCaptcha = oxNew('oxCaptcha');
00060         if (!$oCaptcha->pass($sMac, $sMacHash)) {
00061             $this->_iPriceAlarmStatus = 2;
00062 
00063             return;
00064         }
00065 
00066         $aParams = oxRegistry::getConfig()->getRequestParameter('pa');
00067         if (!isset($aParams['email']) || !$myUtils->isValidEmail($aParams['email'])) {
00068             $this->_iPriceAlarmStatus = 0;
00069 
00070             return;
00071         }
00072 
00073         $oCur = $myConfig->getActShopCurrencyObject();
00074         // convert currency to default
00075         $dPrice = $myUtils->currency2Float($aParams['price']);
00076 
00077         $oAlarm = oxNew("oxpricealarm");
00078         $oAlarm->oxpricealarm__oxuserid = new oxField(oxRegistry::getSession()->getVariable('usr'));
00079         $oAlarm->oxpricealarm__oxemail = new oxField($aParams['email']);
00080         $oAlarm->oxpricealarm__oxartid = new oxField($aParams['aid']);
00081         $oAlarm->oxpricealarm__oxprice = new oxField($myUtils->fRound($dPrice, $oCur));
00082         $oAlarm->oxpricealarm__oxshopid = new oxField($myConfig->getShopId());
00083         $oAlarm->oxpricealarm__oxcurrency = new oxField($oCur->name);
00084 
00085         $oAlarm->oxpricealarm__oxlang = new oxField(oxRegistry::getLang()->getBaseLanguage());
00086 
00087         $oAlarm->save();
00088 
00089         // Send Email
00090         $oEmail = oxNew('oxemail');
00091         $this->_iPriceAlarmStatus = (int) $oEmail->sendPricealarmNotification($aParams, $oAlarm);
00092     }
00093 
00099     public function getBidPrice()
00100     {
00101         if ($this->_sBidPrice === null) {
00102             $this->_sBidPrice = false;
00103 
00104             $aParams = $this->_getParams();
00105             $oCur = $this->getConfig()->getActShopCurrencyObject();
00106             $iPrice = oxRegistry::getUtils()->currency2Float($aParams['price']);
00107             $this->_sBidPrice = oxRegistry::getLang()->formatCurrency($iPrice, $oCur);
00108         }
00109 
00110         return $this->_sBidPrice;
00111     }
00112 
00118     public function getProduct()
00119     {
00120         if ($this->_oArticle === null) {
00121             $this->_oArticle = false;
00122             $aParams = $this->_getParams();
00123             $oArticle = oxNew('oxarticle');
00124             $oArticle->load($aParams['aid']);
00125             $this->_oArticle = $oArticle;
00126         }
00127 
00128         return $this->_oArticle;
00129     }
00130 
00136     private function _getParams()
00137     {
00138         return oxRegistry::getConfig()->getRequestParameter('pa');
00139     }
00140 
00146     public function getPriceAlarmStatus()
00147     {
00148         return $this->_iPriceAlarmStatus;
00149     }
00150 }