pricealarm_send.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class PriceAlarm_Send extends oxAdminList
00008 {
00014     protected $_iDefEdit = 1;
00022     public function render()
00023     {
00024         $myConfig  = $this->getConfig();
00025         $oDB = oxDb::getDb();
00026 
00027         parent::render();
00028 
00029         ini_set("session.gc_maxlifetime", 36000);
00030 
00031         $iStart     = oxConfig::getParameter( "iStart");
00032         $iAllCnt    = oxConfig::getParameter( "iAllCnt");
00033             // #1140 R
00034             $sSelect = "select oxpricealarm.oxid, oxpricealarm.oxemail, oxpricealarm.oxartid, oxpricealarm.oxprice from oxpricealarm, oxarticles where oxarticles.oxid = oxpricealarm.oxartid and oxpricealarm.oxsended = '0000-00-00 00:00:00'";
00035             if (isset($iStart)) {
00036                 $rs = $oDB->SelectLimit( $sSelect, $myConfig->getConfigParam( 'iCntofMails' ), $iStart);
00037             } else {
00038                 $rs = $oDB->Execute( $sSelect);
00039             }
00040 
00041             $iAllCntTmp=0;
00042 
00043             if ($rs != false && $rs->recordCount() > 0) {
00044                 while (!$rs->EOF) {
00045                     $oArticle = oxNew("oxarticle" );
00046                     $oArticle->load($rs->fields['oxid']);
00047                     if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields['oxprice']) {
00048                         $this->sendeMail( $rs->fields['oxemail'], $rs->fields['oxartid'], $rs->fields['oxid'], $rs->fields['oxprice']);
00049                         $iAllCntTmp++;
00050                     }
00051                     $rs->moveNext();
00052                 }
00053             }
00054             if ( !isset( $iStart)) {
00055                 // first call
00056                 $iStart     = 0;
00057                 $iAllCnt    = $iAllCntTmp;
00058             }
00059 
00060 
00061         // adavance mail pointer and set parameter
00062         $iStart += $myConfig->getConfigParam( 'iCntofMails' );
00063 
00064         $this->_aViewData["iStart"]  =  $iStart;
00065         $this->_aViewData["iAllCnt"] =  $iAllCnt;
00066         $this->_aViewData["actlang"] = oxLang::getInstance()->getBaseLanguage();
00067 
00068         // end ?
00069         if ( $iStart < $iAllCnt)
00070             $sPage = "pricealarm_send.tpl";
00071         else
00072             $sPage = "pricealarm_done.tpl";
00073 
00074         return $sPage;
00075     }
00076 
00084     protected function _setupNavigation( $sId )
00085     {
00086         parent::_setupNavigation( 'pricealarm_list' );
00087     }
00088 
00099     public function sendeMail( $sEMail, $sProductID, $sPricealarmID, $sBidPrice )
00100     {
00101         $myConfig = $this->getConfig();
00102         $oAlarm = oxNew( "oxpricealarm" );
00103         $oAlarm->load( $sPricealarmID );
00104 
00105         // Send Email
00106         $oShop = oxNew( "oxshop" );
00107         $oShop->load( $oAlarm->oxpricealarm__oxshopid->value);
00108         $oShop = $this->addGlobalParams( $oShop);
00109 
00110         $oArticle = oxNew( "oxarticle" );
00111         $oArticle->load( $sProductID );
00112 
00113         if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00114             $oParent = oxNew( "oxarticle" );
00115             $oParent->load($oArticle->oxarticles__oxparentid->value);
00116             $oArticle->oxarticles__oxtitle->setValue($oParent->oxarticles__oxtitle->value." ".$oArticle->oxarticles__oxvarselect->value);
00117         }
00118 
00119         $oDefCurr = $myConfig->getActShopCurrencyObject();
00120 
00121         if ( ! ( $oThisCurr = $myConfig->getCurrencyObject( $oAlarm->oxpricealarm__oxcurrency->value ) ) ) {
00122             $oThisCurr = $oDefCurr;
00123             $oAlarm->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00124         }
00125 
00126         // #889C - Netto prices in Admin
00127         // (we have to call $oArticle->getPrice() to get price with VAT)
00128         $oLang = oxLang::getInstance();
00129         $oArticle->oxarticles__oxprice->setValue($oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate);
00130         $oArticle->fprice = $oLang->formatCurrency( $oArticle->oxarticles__oxprice->value, $oThisCurr);
00131         $oAlarm->fpricealarmprice = $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oThisCurr);
00132 
00133         $oxEMail = oxNew( "oxemail" );
00134         $oxEMail->From     = $oShop->oxshops__oxorderemail->value;
00135         $oxEMail->FromName = $oShop->oxshops__oxname->getRawValue();
00136         $oxEMail->Host     = $oShop->oxshops__oxsmtp->value;
00137         $oxEMail->SetSMTP( $oShop);
00138         $oxEMail->WordWrap = 100;
00139 
00140         // create messages
00141         $smarty = oxUtilsView::getInstance()->getSmarty();
00142         $smarty->assign( "shop", $oShop );
00143         $smarty->assign( "product", $oArticle );
00144         $smarty->assign( "bidprice", $oLang->formatCurrency( $sBidPrice, $oThisCurr ) );
00145         $smarty->assign( "currency", $oThisCurr );
00146         $smarty->assign( "shopImageDir", $myConfig->getImageUrl( false, false ) );
00147 
00148         $iLang = (int) $oAlarm->oxpricealarm__oxlang->value;
00149 
00150         $iOldLangId = $oLang->getTplLanguage();
00151         $oLang->setTplLanguage( $iLang );
00152 
00153         $oxEMail->setBody( $smarty->fetch( "email_pricealarm_customer.tpl" ) );
00154         $oxEMail->setSubject( $oShop->oxshops__oxname->getRawValue() );
00155         $oxEMail->addAddress( $sEMail, $sEMail );
00156         $oxEMail->addReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
00157         $blSuccess = $oxEMail->send();
00158 
00159         $oLang->setTplLanguage( $iOldLangId );
00160 
00161         if ( $blSuccess ) {
00162             $oAlarm->oxpricealarm__oxsended->setValue( date( "Y-m-d H:i:s" ) );
00163             $oAlarm->save();
00164         }
00165 
00166     }
00167 }