pricealarm_send.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class PriceAlarm_Send extends oxAdminList
00009 {
00015     protected $_iDefEdit = 1;
00023     public function render()
00024     {
00025         $myConfig  = $this->getConfig();
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 = oxDb::getDb()->SelectLimit( $sSelect, $myConfig->getConfigParam( 'iCntofMails' ), $iStart);
00037             else
00038                 $rs = oxDb::getDb()->Execute( $sSelect);
00039 
00040             $iAllCnt_counting=0;
00041 
00042             if ($rs != false && $rs->recordCount() > 0) {
00043                 while (!$rs->EOF) {
00044                     $oArticle = oxNew("oxarticle" );
00045                     $oArticle->load($rs->fields[2]);
00046                     if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields[3]) {
00047                         $this->sendeMail( $rs->fields[1], $rs->fields[2], $rs->fields[0], $rs->fields[3]);
00048                         $iAllCnt_counting++;
00049                     }
00050                     $rs->moveNext();
00051                 }
00052             }
00053             if ( !isset( $iStart)) {
00054                 // first call
00055                 $iStart     = 0;
00056                 $iAllCnt    = $iAllCnt_counting;
00057             }
00058 
00059 
00060         // adavance mail pointer and set parameter
00061         $iStart += $myConfig->getConfigParam( 'iCntofMails' );
00062 
00063         $this->_aViewData["iStart"]  =  $iStart;
00064         $this->_aViewData["iAllCnt"] =  $iAllCnt;
00065         $this->_aViewData["actlang"] = oxLang::getInstance()->getBaseLanguage();
00066 
00067         // end ?
00068         if ( $iStart < $iAllCnt)
00069             $sPage = "pricealarm_send.tpl";
00070         else
00071             $sPage = "pricealarm_done.tpl";
00072 
00073         return $sPage;
00074     }
00075 
00081     protected function _setupNavigation( $sId )
00082     {
00083         parent::_setupNavigation( 'pricealarm_list' );
00084     }
00085 
00096     public function sendeMail( $sEMail, $sProductID, $sPricealarmID, $sBidPrice)
00097     {
00098         $myConfig = $this->getConfig();
00099         $oPricealarm = oxNew( "oxpricealarm" );
00100         $oPricealarm->load( $sPricealarmID);
00101 
00102         // Send Email
00103         $oShop = oxNew( "oxshop" );
00104         //$oShop->load( $myConfig->getShopId());
00105         $oShop->load( $oPricealarm->oxpricealarm__oxshopid->value);
00106         $oShop = $this->addGlobalParams( $oShop);
00107 
00108         $oArticle = oxNew( "oxarticle" );
00109         $oArticle->load( $sProductID);
00110 
00111         if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00112             $oParent = oxNew( "oxarticle" );
00113             $oParent->load($oArticle->oxarticles__oxparentid->value);
00114             $oArticle->oxarticles__oxtitle->setValue($oParent->oxarticles__oxtitle->value." ".$oArticle->oxarticles__oxvarselect->value);
00115         }
00116 
00117         $oDefCurr = $myConfig->getActShopCurrencyObject();
00118 
00119         $oAlarm = oxNew( "oxpricealarm" );
00120         $oAlarm->load( $sPricealarmID);
00121 
00122         $oThisCurr = $myConfig->getCurrencyObject( $oAlarm->oxpricealarm__oxcurrency->value);
00123 
00124         if ( !$oThisCurr ) {
00125             $oThisCurr = $oDefCurr;
00126             $oAlarm->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00127         }
00128 
00129         // #889C - Netto prices in Admin
00130         // (we have to call $oArticle->getPrice() to get price with VAT)
00131         $oArticle->oxarticles__oxprice->setValue($oArticle->getPrice() * $oThisCurr->rate);
00132         $oArticle->fprice = oxLang::getInstance()->formatCurrency( $oArticle->oxarticles__oxprice->value, $oThisCurr);
00133         $oAlarm->fpricealarmprice = oxLang::getInstance()->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oThisCurr);
00134 
00135         $oxEMail = oxNew( "oxemail" );
00136         $oxEMail->From     = $oShop->oxshops__oxorderemail->value;
00137         $oxEMail->FromName = $oShop->oxshops__oxname->value;
00138         $oxEMail->Host     = $oShop->oxshops__oxsmtp->value;
00139         $oxEMail->SetSMTP( $oShop);
00140         $oxEMail->WordWrap = 100;
00141 
00142         // create messages
00143         $smarty = oxUtilsView::getInstance()->getSmarty();
00144         $smarty->assign( "shop", $oShop );
00145         $smarty->assign( "product", $oArticle );
00146         $smarty->assign( "bidprice", oxLang::getInstance()->formatCurrency($sBidPrice, $oThisCurr) );
00147         $smarty->assign( "currency", $oThisCurr );
00148         $smarty->assign( "shopImageDir", $myConfig->getImageUrl( false , false ) );
00149 
00150         $iLang = @$oAlarm->oxpricealarm__oxlang->value;
00151         if (!$iLang)
00152             $iLang = 0;
00153 
00154         $old_iLang = oxLang::getInstance()->getTplLanguage();
00155         oxLang::getInstance()->setTplLanguage( $iLang );
00156 
00157         $oxEMail->Body      = $smarty->fetch( "email_pricealarm_customer.tpl");
00158         $oxEMail->Subject   = $oShop->oxshops__oxname->value;
00159         $oxEMail->AddAddress( $sEMail, $sEMail );
00160         $oxEMail->AddReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value);
00161         $blSuccess = $oxEMail->send();
00162 
00163         oxLang::getInstance()->setTplLanguage( $old_iLang );
00164 
00165         if ( $blSuccess) {
00166             $timeout = time();
00167             $now = date("Y-m-d H:i:s", $timeout);
00168             $oAlarm->oxpricealarm__oxsended->setValue($now);
00169             $oAlarm->save();
00170         }
00171 
00172     }
00173 }

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