pricealarm_main.php

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

Generated by  doxygen 1.6.2