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             $iAllCnt_counting=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                         $iAllCnt_counting++;
00050                     }
00051                     $rs->moveNext();
00052                 }
00053             }
00054             if ( !isset( $iStart)) {
00055                 // first call
00056                 $iStart     = 0;
00057                 $iAllCnt    = $iAllCnt_counting;
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 
00082     protected function _setupNavigation( $sId )
00083     {
00084         parent::_setupNavigation( 'pricealarm_list' );
00085     }
00086 
00097     public function sendeMail( $sEMail, $sProductID, $sPricealarmID, $sBidPrice)
00098     {
00099         $myConfig = $this->getConfig();
00100         $oPricealarm = oxNew( "oxpricealarm" );
00101         $oPricealarm->load( $sPricealarmID);
00102 
00103         // Send Email
00104         $oShop = oxNew( "oxshop" );
00105         //$oShop->load( $myConfig->getShopId());
00106         $oShop->load( $oPricealarm->oxpricealarm__oxshopid->value);
00107         $oShop = $this->addGlobalParams( $oShop);
00108 
00109         $oArticle = oxNew( "oxarticle" );
00110         $oArticle->load( $sProductID);
00111 
00112         if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00113             $oParent = oxNew( "oxarticle" );
00114             $oParent->load($oArticle->oxarticles__oxparentid->value);
00115             $oArticle->oxarticles__oxtitle->setValue($oParent->oxarticles__oxtitle->value." ".$oArticle->oxarticles__oxvarselect->value);
00116         }
00117 
00118         $oDefCurr = $myConfig->getActShopCurrencyObject();
00119 
00120         $oAlarm = oxNew( "oxpricealarm" );
00121         $oAlarm->load( $sPricealarmID);
00122 
00123         $oThisCurr = $myConfig->getCurrencyObject( $oAlarm->oxpricealarm__oxcurrency->value);
00124 
00125         if ( !$oThisCurr ) {
00126             $oThisCurr = $oDefCurr;
00127             $oAlarm->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00128         }
00129 
00130         // #889C - Netto prices in Admin
00131         // (we have to call $oArticle->getPrice() to get price with VAT)
00132         $oLang = oxLang::getInstance();
00133         $oArticle->oxarticles__oxprice->setValue($oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate);
00134         $oArticle->fprice = $oLang->formatCurrency( $oArticle->oxarticles__oxprice->value, $oThisCurr);
00135         $oAlarm->fpricealarmprice = $oLang->formatCurrency( $oAlarm->oxpricealarm__oxprice->value, $oThisCurr);
00136 
00137         $oxEMail = oxNew( "oxemail" );
00138         $oxEMail->From     = $oShop->oxshops__oxorderemail->value;
00139         $oxEMail->FromName = $oShop->oxshops__oxname->getRawValue();
00140         $oxEMail->Host     = $oShop->oxshops__oxsmtp->value;
00141         $oxEMail->SetSMTP( $oShop);
00142         $oxEMail->WordWrap = 100;
00143 
00144         // create messages
00145         $smarty = oxUtilsView::getInstance()->getSmarty();
00146         $smarty->assign( "shop", $oShop );
00147         $smarty->assign( "product", $oArticle );
00148         $smarty->assign( "bidprice", $oLang->formatCurrency($sBidPrice, $oThisCurr) );
00149         $smarty->assign( "currency", $oThisCurr );
00150         $smarty->assign( "shopImageDir", $myConfig->getImageUrl( false , false ) );
00151 
00152         $iLang = $oAlarm->oxpricealarm__oxlang->value;
00153 
00154         if (!$iLang) {
00155             $iLang = 0;
00156         }
00157 
00158         $old_iLang = $oLang->getTplLanguage();
00159         $oLang->setTplLanguage( $iLang );
00160 
00161         $oxEMail->Body      = $smarty->fetch( "email_pricealarm_customer.tpl");
00162         $oxEMail->Subject   = $oShop->oxshops__oxname->getRawValue();
00163         $oxEMail->AddAddress( $sEMail, $sEMail );
00164         $oxEMail->AddReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->getRawValue());
00165         $blSuccess = $oxEMail->send();
00166 
00167         $oLang->setTplLanguage( $old_iLang );
00168 
00169         if ( $blSuccess) {
00170             $oAlarm->oxpricealarm__oxsended->setValue( date( "Y-m-d H:i:s" ) );
00171             $oAlarm->save();
00172         }
00173 
00174     }
00175 }

Generated on Tue Aug 18 09:21:05 2009 for OXID eShop CE by  doxygen 1.5.5