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         $myUtils  = oxUtils::getInstance();
00073 
00074         //control captcha
00075         $sMac     = oxConfig::getParameter( 'c_mac' );
00076         $sMacHash = oxConfig::getParameter( 'c_mach' );
00077         $oCaptcha = oxNew('oxCaptcha');
00078         if (!$oCaptcha->pass($sMac, $sMacHash)) {
00079             $this->_iPriceAlarmStatus = 2;
00080             return;
00081         }
00082 
00083 
00084 
00085         $aParams = oxConfig::getParameter( 'pa' );
00086         if ( !isset( $aParams['email'] ) || !$myUtils->isValidEmail( $aParams['email'] ) ) {
00087             $this->_iPriceAlarmStatus = 0;
00088             return;
00089         }
00090 
00091         $oCur = $myConfig->getActShopCurrencyObject();
00092         // convert currency to default
00093         $dPrice = $myUtils->currency2Float( $aParams['price'] );
00094 
00095         $oAlarm = oxNew( "oxpricealarm" );
00096         $oAlarm->oxpricealarm__oxuserid = new oxField( oxSession::getVar( 'usr' ));
00097         $oAlarm->oxpricealarm__oxemail  = new oxField( $aParams['email']);
00098         $oAlarm->oxpricealarm__oxartid  = new oxField( $aParams['aid']);
00099         $oAlarm->oxpricealarm__oxprice  = new oxField( $myUtils->fRound( $dPrice, $oCur ));
00100         $oAlarm->oxpricealarm__oxshopid = new oxField( $myConfig->getShopId());
00101         $oAlarm->oxpricealarm__oxcurrency = new oxField( $oCur->name);
00102 
00103         $oAlarm->oxpricealarm__oxlang = new oxField(oxLang::getInstance()->getBaseLanguage());
00104 
00105         $oAlarm->save();
00106 
00107         // Send Email
00108         $oEmail = oxNew( 'oxemail' );
00109         $this->_iPriceAlarmStatus = (int) $oEmail->sendPricealarmNotification( $aParams, $oAlarm );
00110     }
00111 
00117     public function getBidPrice()
00118     {
00119         if ( $this->_sBidPrice === null ) {
00120             $this->_sBidPrice = false;
00121 
00122             $aParams = $this->_getParams();
00123             $oCur = $this->getConfig()->getActShopCurrencyObject();
00124             $iPrice = oxUtils::getInstance()->currency2Float( $aParams['price'] );
00125             $this->_sBidPrice = oxLang::getInstance()->formatCurrency( $iPrice, $oCur );
00126         }
00127         return $this->_sBidPrice;
00128     }
00129 
00135     public function getProduct()
00136     {
00137         if ( $this->_oArticle === null ) {
00138             $this->_oArticle = false;
00139             $aParams = $this->_getParams();
00140             $oArticle = oxNew( 'oxarticle' );
00141             $oArticle->load( $aParams['aid'] );
00142             $this->_oArticle = $oArticle;
00143         }
00144         return $this->_oArticle;
00145     }
00146 
00152     private function _getParams()
00153     {
00154         return oxConfig::getParameter( 'pa' );
00155     }
00156 
00162     public function getPriceAlarmStatus()
00163     {
00164         return $this->_iPriceAlarmStatus;
00165     }
00166 
00167 }

Generated by  doxygen 1.6.2