pricealarm_main.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class PriceAlarm_Main extends oxAdminDetails
00010 {
00018     public function render()
00019     {   $myConfig = $this->getConfig();
00020 
00021             // #1140 R - price must be checked from the object.
00022             $sql = "select oxarticles.oxid, oxpricealarm.oxprice from oxpricealarm, oxarticles where oxarticles.oxid = oxpricealarm.oxartid and oxpricealarm.oxsended = '000-00-00 00:00:00'";
00023             $rs = oxDb::getDb()->Execute( $sql);
00024             $iAllCnt_counting = 0;
00025             if ($rs != false && $rs->recordCount() > 0) {
00026                 while (!$rs->EOF) {
00027                     $oArticle = oxNew("oxarticle" );
00028                     $oArticle->load($rs->fields[0]);
00029                     if ($oArticle->getPrice()->getBruttoPrice() <= $rs->fields[1])
00030                         $iAllCnt_counting++;
00031                     $rs->moveNext();
00032                 }
00033             }
00034             $this->_aViewData['iAllCnt'] = $iAllCnt_counting;
00035 
00036         $soxId = oxConfig::getParameter( "oxid");
00037         // check if we right now saved a new entry
00038         $sSavedID = oxConfig::getParameter( "saved_oxid");
00039         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00040             $soxId = $sSavedID;
00041             oxSession::deleteVar( "saved_oxid");
00042             $this->_aViewData["oxid"] =  $soxId;
00043             // for reloading upper frame
00044             $this->_aViewData["updatelist"] =  "1";
00045         }
00046 
00047         if ( $soxId != "-1" && isset( $soxId)) {
00048             // load object
00049             $oPricealarm = oxNew( "oxpricealarm" );
00050             $oPricealarm->load( $soxId);
00051 
00052             $oDefCurr = $myConfig->getActShopCurrencyObject();
00053             $oArticle = oxNew( "oxarticle" );
00054             $oArticle->load($oPricealarm->oxpricealarm__oxartid->value);
00055 
00056             if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00057                 $oParent = oxNew( "oxarticle" );
00058                 $oParent->load($oArticle->oxarticles__oxparentid->value);
00059                 $oArticle->oxarticles__oxtitle->setValue($oParent->oxarticles__oxtitle->value." ".$oArticle->oxarticles__oxvarselect->value);
00060             }
00061 
00062 
00063             $oThisCurr = $myConfig->getCurrencyObject( $oPricealarm->oxpricealarm__oxcurrency->value);
00064 
00065             if ( !$oThisCurr ) {
00066                 $oThisCurr = $oDefCurr;
00067                 $oPricealarm->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00068             }
00069 
00070             // #889C - Netto prices in Admin
00071             // (we have to call $oArticle->getPrice() to get price with VAT)
00072             $oArticle->oxarticles__oxprice->setValue($oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate);
00073             $oArticle->fprice = oxLang::getInstance()->formatCurrency( $oArticle->oxarticles__oxprice->value, $oThisCurr);
00074 
00075             $oPricealarm->oxpricealarm__oxprice->setValue(oxLang::getInstance()->formatCurrency( $oPricealarm->oxpricealarm__oxprice->value, $oThisCurr));
00076 
00077             $oPricealarm->oArticle = $oArticle;
00078             $oCur = $myConfig->getCurrencyObject( $oPricealarm->oxpricealarm__oxcurrency->value);
00079 
00080             // customer info
00081             $oUser = null;
00082             if ( $oPricealarm->oxpricealarm__oxuserid->value) {
00083                 $oUser = oxNew( "oxuser" );
00084                 $oUser->load($oPricealarm->oxpricealarm__oxuserid->value);
00085                 $oPricealarm->oUser = $oUser;
00086             }
00087             //
00088             $oShop = oxNew( "oxshop" );
00089             $oShop->load( $myConfig->getShopId());
00090             $oShop = $this->addGlobalParams( $oShop);
00091 
00092             $smarty = oxUtilsView::getInstance()->getSmarty();
00093             $smarty->assign( "shop", $oShop );
00094             $smarty->assign( "product", $oArticle );
00095             $smarty->assign( "bidprice", $oPricealarm->oxpricealarm__oxprice->value);
00096             $smarty->assign( "shopImageDir", $myConfig->getImageUrl( false , false ) );
00097             $smarty->assign( "currency", $oCur );
00098 
00099             $iLang = @$oPricealarm->oxpricealarm__oxlang->value;
00100             if (!$iLang)
00101                 $iLang = 0;
00102             $aLanguages = oxLang::getInstance()->getLanguageNames();
00103             $this->_aViewData["edit_lang"] = $aLanguages[$iLang];
00104             // rendering mail message text
00105             $oLetter = new oxStdClass();
00106             $aParams = oxConfig::getParameter( "editval");
00107             if ( isset( $aParams['oxpricealarm__oxlongdesc'] ) && $aParams['oxpricealarm__oxlongdesc'] ) {
00108                 $oLetter->oxpricealarm__oxlongdesc = new oxField( stripslashes( $aParams['oxpricealarm__oxlongdesc'] ), oxField::T_RAW );
00109             } else {
00110                 $old_iLang = oxLang::getInstance()->getTplLanguage();
00111                 oxLang::getInstance()->setTplLanguage( $iLang );
00112                 $smarty->fetch( "email_pricealarm_customer.tpl");
00113 
00114                 $oLetter->oxpricealarm__oxlongdesc = new oxField( $smarty->fetch( "email_pricealarm_customer.tpl"), oxField::T_RAW );
00115                 oxLang::getInstance()->setTplLanguage( $old_iLang );
00116             }
00117 
00118             $this->_aViewData["editor"]  = $this->_generateTextEditor( "100%", 300, $oLetter, "oxpricealarm__oxlongdesc", "details.tpl.css");
00119             $this->_aViewData["edit"] =  $oPricealarm;
00120             $this->_aViewData["oxid"] = $soxId;
00121             $this->_aViewData["actshop"] = $oShop->getShopId();
00122         }
00123 
00124         parent::render();
00125 
00126         return "pricealarm_main.tpl";
00127     }
00128 
00134     public function send()
00135     {
00136         // error
00137         if ( !oxConfig::getParameter( "oxid")) {
00138             $this->_aViewData["mail_err"] = 1;
00139             return;
00140         }
00141 
00142         $oPricealarm = oxNew( "oxpricealarm" );
00143         $oPricealarm->load( oxConfig::getParameter( "oxid"));
00144 
00145         // Send Email
00146         $oShop = oxNew( "oxshop" );
00147         $oShop->load( $oPricealarm->oxpricealarm__oxshopid->value);
00148         $oShop = $this->addGlobalParams( $oShop);
00149 
00150         $oArticle = oxNew( "oxarticle" );
00151         $oArticle->load( $oPricealarm->oxpricealarm__oxartid->value);
00152 
00153         //arranging user email
00154         $oxEMail = oxNew( "oxemail" );
00155         $oxEMail->From     = $oShop->oxshops__oxorderemail->value;
00156         $oxEMail->FromName = $oShop->oxshops__oxname->value;
00157         $oxEMail->Host     = $oShop->oxshops__oxsmtp->value;
00158         $oxEMail->SetSMTP( $oShop);
00159         $oxEMail->WordWrap = 100;
00160 
00161         $aParams = oxConfig::getParameter( "editval" );
00162         $oxEMail->Body      = stripslashes( isset( $aParams['oxpricealarm__oxlongdesc'] ) ? $aParams['oxpricealarm__oxlongdesc'] : '' );
00163         $oxEMail->Subject   = $oShop->oxshops__oxname->value;
00164         $oxEMail->AddAddress( $oPricealarm->oxpricealarm__oxemail->value, $oPricealarm->oxpricealarm__oxemail->value );
00165         $oxEMail->AddReplyTo( $oShop->oxshops__oxorderemail->value, $oShop->oxshops__oxname->value);
00166         $blSuccess = $oxEMail->send();
00167 
00168         // setting result message
00169         if ( $blSuccess) {
00170             $timeout = time();
00171             $now = date("Y-m-d H:i:s", $timeout);
00172             $oPricealarm->oxpricealarm__oxsended->setValue($now);
00173             $oPricealarm->save();
00174             $this->_aViewData["mail_succ"] = 1;
00175         } else {
00176             $this->_aViewData["mail_err"] = 1;
00177         }
00178     }
00179 }

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