pricealarm.php

Go to the documentation of this file.
00001 <?php
00002 
00011 class Pricealarm extends oxUBase
00012 {
00017     protected $_sThisTemplate = 'pricealarm.tpl';
00018 
00023     protected $_oArticle = null;
00024 
00029     protected $_sBidPrice = null;
00030 
00035     protected $_iPriceAlarmStatus = null;
00036 
00046     public function render()
00047     {
00048         parent::render();
00049 
00050         $this->_aViewData['product']  = $this->getProduct();
00051         $this->_aViewData['bidprice'] = $this->getBidPrice();
00052         $this->_aViewData['success']  = $this->getPriceAlarmStatus();
00053 
00054         return $this->_sThisTemplate;
00055     }
00056 
00069     public function addme()
00070     {
00071         $myConfig = $this->getConfig();
00072 
00073         //control captcha
00074         $sMac     = oxConfig::getParameter( 'c_mac' );
00075         $sMacHash = oxConfig::getParameter( 'c_mach' );
00076         $oCaptcha = oxNew('oxCaptcha');
00077         if (!$oCaptcha->pass($sMac, $sMacHash)) {
00078             $this->_iPriceAlarmStatus = '0';
00079             return;
00080         }
00081 
00082 
00083 
00084         $aParams = oxConfig::getParameter( 'pa' );
00085         if ( !isset( $aParams['email'] ) || !oxUtils::getInstance()->isValidEmail( $aParams['email'] ) ) {
00086             $this->_iPriceAlarmStatus = "0";
00087             return;
00088         }
00089 
00090         $oCur = $myConfig->getActShopCurrencyObject();
00091         // convert currency to default
00092         $dPrice = oxUtils::getInstance()->currency2Float( $aParams['price'] );
00093 
00094         $oAlarm = oxNew( "oxpricealarm" );
00095         $oAlarm->oxpricealarm__oxuserid = new oxField(oxSession::getVar( 'usr' ));
00096         $oAlarm->oxpricealarm__oxemail  = new oxField($aParams['email']);
00097         $oAlarm->oxpricealarm__oxartid  = new oxField($aParams['aid']);
00098         $oAlarm->oxpricealarm__oxprice  = new oxField(oxUtils::getInstance()->fRound( $dPrice, $oCur ));
00099         $oAlarm->oxpricealarm__oxshopid = new oxField($myConfig->getShopId());
00100         $oAlarm->oxpricealarm__oxcurrency = new oxField($oCur->name);
00101 
00102             $oAlarm->oxpricealarm__oxlang = new oxField(oxLang::getInstance()->getBaseLanguage());
00103 
00104         $oAlarm->save();
00105 
00106         // Send Email
00107         $oEmail = oxNew( 'oxemail' );
00108         $this->_iPriceAlarmStatus = $oEmail->sendPricealarmNotification( $aParams, $oAlarm );
00109     }
00110 
00116     public function getBidPrice()
00117     {
00118         if ( $this->_sBidPrice === null ) {
00119             $this->_sBidPrice = false;
00120 
00121             $aParams = $this->_getParams();
00122             $oCur = $this->getConfig()->getActShopCurrencyObject();
00123             $iPrice = oxUtils::getInstance()->currency2Float( $aParams['price'] );
00124             $this->_sBidPrice = oxLang::getInstance()->formatCurrency( $iPrice, $oCur );
00125         }
00126         return $this->_sBidPrice;
00127     }
00128 
00134     public function getProduct()
00135     {
00136         if ( $this->_oArticle === null ) {
00137             $this->_oArticle = false;
00138             $aParams = $this->_getParams();
00139             $oArticle = oxNew( 'oxarticle' );
00140             $oArticle->load( $aParams['aid'] );
00141             $this->_oArticle = $oArticle;
00142         }
00143         return $this->_oArticle;
00144     }
00145 
00151     private function _getParams()
00152     {
00153         return oxConfig::getParameter( 'pa' );
00154     }
00155 
00161     public function getPriceAlarmStatus()
00162     {
00163         return $this->_iPriceAlarmStatus;
00164     }
00165 
00166 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5