oxorder.php

Go to the documentation of this file.
00001 <?php
00002 
00006 require_once oxConfig::getInstance()->getConfigParam( 'sCoreDir' ) . 'fpdf/oxpdf.php';
00007 
00013 class oxOrder extends oxBase
00014 {
00015 
00021     protected $_aSkipSaveFields = array( 'oxorderdate' );
00022 
00028     protected $_oArticles = null;
00029 
00035     protected $_oDelSet   = null;
00036 
00042     protected $_oGiftCard = null;
00043 
00049     protected $_oPaymentType = null;
00050 
00056     protected $_oPayment = null;
00057 
00063     protected $_aVoucherList = null;
00064 
00070     protected $_oDelPrice = null;
00071 
00077     protected $_oUser = null;
00078 
00084     protected $_oBasket = null;
00085 
00091     protected $_oWrappingPrice = null;
00092 
00098     protected $_oPaymentPrice = null;
00099 
00105     protected $_sClassName = 'oxorder';
00106 
00112     protected $_blSeparateNumbering = null;
00113 
00119     protected $_iOrderLang = null;
00120 
00124     public function __construct()
00125     {
00126         parent::__construct();
00127         $this->init( 'oxorder' );
00128 
00129         // set usage of seperate orders numbering for different shops
00130         $this->setSeparateNumbering( $this->getConfig()->getConfigParam( 'blSeparateNumbering') );
00131 
00132     }
00133 
00141     public function __get( $sName )
00142     {
00143         if ( $sName == 'oDelSet' ) {
00144             return $this->getDelSet();
00145         }
00146     }
00147 
00155     public function assign( $dbRecord )
00156     {
00157 
00158         parent::assign( $dbRecord );
00159 
00160         // convert date's to international format
00161         $this->oxorder__oxorderdate = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxorder__oxorderdate->value ), oxField::T_RAW);
00162         $this->oxorder__oxsenddate  = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxorder__oxsenddate->value ), oxField::T_RAW);
00163 
00164 
00165         //get billing country name from billing country id
00166         if ( !$this->oxorder__oxbillcountry->value ) {
00167             $this->oxorder__oxbillcountry = new oxField($this->_getCountryTitle( $this->oxorder__oxbillcountryid->value ));
00168         }
00169 
00170         //get delivery country name from delivery country id
00171         if ( !$this->oxorder__oxdelcountry->value ) {
00172              $this->oxorder__oxdelcountry = new oxField($this->_getCountryTitle( $this->oxorder__oxdelcountryid->value ));
00173         }
00174 
00175         //settting deprecated template variables
00176         $this->_setDeprecatedValues();
00177     }
00178 
00186     protected function _getCountryTitle( $sCountryId )
00187     {
00188         $sTitle = null;
00189         if ( $sCountryId && $sCountryId != '-1' ) {
00190             $oCountry = oxNew( 'oxcountry' );
00191             $oCountry->load( $sCountryId );
00192             $sTitle = $oCountry->oxcountry__oxtitle->value;
00193         }
00194 
00195         return $sTitle;
00196     }
00197 
00203     public function getOrderArticles()
00204     {
00205         if ( $this->_oArticles == null ) {
00206 
00207             // order articles
00208             $this->_oArticles = oxNew( 'oxlist' );
00209             $this->_oArticles->init( 'oxorderarticle' );
00210 
00211             $sSelect = 'select oxorderarticles.* from oxorderarticles
00212                         where oxorderarticles.oxorderid="'.$this->getId().'"
00213                         order by oxorderarticles.oxartid';
00214             $this->_oArticles->selectString( $sSelect );
00215         }
00216 
00217         return $this->_oArticles;
00218     }
00219 
00225     public function getOrderDeliveryPrice()
00226     {
00227         if ( $this->_oDelPrice != null ) {
00228             return $this->_oDelPrice;
00229         }
00230 
00231         $this->_oDelPrice = oxNew( 'oxprice' );
00232         $this->_oDelPrice->setBruttoPriceMode();
00233         $this->_oDelPrice->setPrice( $this->oxorder__oxdelcost->value, $this->oxorder__oxdelvat->value );
00234         return $this->_oDelPrice;
00235     }
00236 
00242     public function getOrderWrappingPrice()
00243     {
00244         if ( $this->_oWrappingPrice != null ) {
00245             return $this->_oWrappingPrice;
00246         }
00247 
00248         $this->_oWrappingPrice = oxNew( 'oxprice' );
00249         $this->_oWrappingPrice->setBruttoPriceMode();
00250         $this->_oWrappingPrice->setPrice( $this->oxorder__oxwrapcost->value, $this->oxorder__oxwrapvat->value );
00251         return $this->_oWrappingPrice;
00252     }
00253 
00259     public function getOrderPaymentPrice()
00260     {
00261         if ( $this->_oPaymentPrice != null ) {
00262             return $this->_oPaymentPrice;
00263         }
00264 
00265         $this->_oPaymentPrice = oxNew( 'oxprice' );
00266         $this->_oPaymentPrice->setBruttoPriceMode();
00267         $this->_oPaymentPrice->setPrice( $this->oxorder__oxpaycost->value, $this->oxorder__oxpayvat->value );
00268         return $this->_oPaymentPrice;
00269     }
00270 
00277     public function getOrderNetSum()
00278     {
00279         $dTotalNetSum = 0;
00280 
00281         $dTotalNetSum += $this->oxorder__oxtotalnetsum->value;
00282         $dTotalNetSum += $this->getOrderDeliveryPrice()->getNettoPrice();
00283         $dTotalNetSum += $this->getOrderWrappingPrice()->getNettoPrice();
00284         $dTotalNetSum += $this->getOrderPaymentPrice()->getNettoPrice();
00285 
00286         return $dTotalNetSum;
00287     }
00288 
00309     public function finalizeOrder( oxBasket $oBasket, $oUser, $blRecalculatingOrder = false )
00310     {
00311         // check if this order is already stored
00312         $sGetChallenge = oxSession::getVar( 'sess_challenge' );
00313         if ( $this->_checkOrderExist( $sGetChallenge ) ) {
00314             oxUtils::getInstance()->logger( 'BLOCKER' );
00315             // we might use this later, this means that somebody klicked like mad on order button
00316             return 3;
00317         }
00318 
00319         // if not recalculating order, use sess_challenge id, else leave old order id
00320         if ( !$blRecalculatingOrder ) {
00321             // use this ID
00322             $this->setId( $sGetChallenge );
00323         }
00324 
00325         // copies user info
00326         $this->_setUser( $oUser );
00327 
00328         // copies basket info
00329         $this->_loadFromBasket( $oBasket );
00330 
00331         // payment information
00332         $oUserPayment = $this->_setPayment( $oBasket->getPaymentId() );
00333 
00334         //saving all order data to DB
00335         $this->save();
00336 
00337         // executing payment (on failure deletes order and returns error code)
00338         // in case when recalcualting order, payment execution is skipped
00339         if ( !$blRecalculatingOrder ) {
00340             $blRet = $this->_executePayment( $oBasket, $oUserPayment );
00341             if ( $blRet !== true ) {
00342                 return $blRet;
00343             }
00344         }
00345 
00346         // deleting remark info only when order is finished
00347         oxSession::deleteVar( 'ordrem' );
00348 
00349         // updating order trans status (success status)
00350         $this->_setOrderStatus( 'OK' );
00351 
00352         // store orderid
00353         $oBasket->setOrderId( $this->getId() );
00354 
00355         // updating bought items stock
00356         $this->_updateStock();
00357 
00358         // updating wish lists
00359         $this->_updateWishlist( $oBasket->getContents(), $oUser );
00360 
00361         // updating users notice list
00362         $this->_updateNoticeList( $oBasket->getContents(), $oUser );
00363 
00364         // marking vouchers as used and sets them to $this->_aVoucherList (will be used in order email)
00365         // skipping this action in case of order recalculation
00366         if ( !$blRecalculatingOrder ) {
00367             $this->_markVouchers( $oBasket, $oUser );
00368         }
00369 
00370         // send order by email to shop owner and current user
00371         // skipping this action in case of order recalculation
00372         if ( !$blRecalculatingOrder ) {
00373             $iRet = $this->_sendOrderByEmail( $oUser, $oBasket, $oUserPayment );
00374         } else {
00375             $iRet = 1;
00376         }
00377 
00378         return $iRet;
00379     }
00380 
00388     protected function _setOrderStatus( $sStatus )
00389     {
00390         $sQ = 'update oxorder set oxtransstatus="'.$sStatus.'" where oxid="'.$this->getId().'" ';
00391         oxDb::getDb()->execute( $sQ );
00392     }
00393 
00404     protected function _loadFromBasket( oxBasket $oBasket )
00405     {
00406         $myConfig = $this->getConfig();
00407 
00408         // store IP Adress - default must be FALSE as it is illegal to store
00409         if ( $myConfig->getConfigParam( 'blStoreIPs' ) ) {
00410             $this->oxorder__oxip = new oxField(oxUtilsServer::getInstance()->getRemoteAddress(), oxField::T_RAW);
00411         }
00412 
00413         // copying main price info
00414         $this->oxorder__oxtotalnetsum   = new oxField(oxUtils::getInstance()->fRound($oBasket->getProductsPrice()->getNettoSum()), oxField::T_RAW);
00415         $this->oxorder__oxtotalbrutsum  = new oxField($oBasket->getProductsPrice()->getBruttoSum(), oxField::T_RAW);
00416         $this->oxorder__oxtotalordersum = new oxField($oBasket->getPrice()->getBruttoPrice(), oxField::T_RAW);
00417 
00418         // payment costs if available
00419         if ( ( $oPaymentCost = $oBasket->getCosts( 'oxpayment' ) ) ) {
00420             $this->oxorder__oxpaycost = new oxField($oPaymentCost->getBruttoPrice(), oxField::T_RAW);
00421             $this->oxorder__oxpayvat  = new oxField($oPaymentCost->getVAT(), oxField::T_RAW);
00422         }
00423 
00424         // delivery info
00425         if ( ( $oDeliveryCost = $oBasket->getCosts( 'oxdelivery' ) ) ) {
00426             $this->oxorder__oxdelcost = new oxField($oDeliveryCost->getBruttoPrice(), oxField::T_RAW);
00427             //V #M382: Save VAT, not VAT value for delivery costs
00428             $this->oxorder__oxdelvat  = new oxField($oDeliveryCost->getVAT(), oxField::T_RAW); //V #M382
00429             $this->oxorder__oxdeltype = new oxField($oBasket->getShippingId(), oxField::T_RAW);
00430         }
00431 
00432         // user remark
00433         $this->oxorder__oxremark = new oxField(oxSession::getVar( 'ordrem' ), oxField::T_RAW);
00434 
00435         // currency
00436         $oCur = $myConfig->getActShopCurrencyObject();
00437         $this->oxorder__oxcurrency = new oxField($oCur->name);
00438         $this->oxorder__oxcurrate  = new oxField($oCur->rate, oxField::T_RAW);
00439 
00440         // store voucherdiscount
00441         if ( ( $oVoucherDiscount = $oBasket->getVoucherDiscount() ) ) {
00442             $this->oxorder__oxvoucherdiscount = new oxField($oVoucherDiscount->getBruttoPrice(), oxField::T_RAW);
00443         }
00444 
00445         // general discount
00446         if ( ( $oTotalDiscount = $oBasket->getTotalDiscount() ) ) {
00447             $this->oxorder__oxdiscount = new oxField($oTotalDiscount->getBruttoPrice(), oxField::T_RAW);
00448         }
00449 
00450         //order language
00451         $this->oxorder__oxlang = new oxField( $this->getOrderLanguage() );
00452 
00453 
00454         // initial status - 'ERROR'
00455         $this->oxorder__oxtransstatus = new oxField('ERROR', oxField::T_RAW);
00456 
00457         // copies basket product info ...
00458         $this->_setOrderArticles( $oBasket->getContents() );
00459 
00460         // copies wrapping info
00461         $this->_setWrapping( $oBasket );
00462     }
00463 
00470     public function getOrderLanguage()
00471     {
00472         if ( $this->_iOrderLang === null ) {
00473             if ( isset( $this->oxorder__oxlang->value ) ) {
00474                 $this->_iOrderLang = oxLang::getInstance()->validateLanguage( $this->oxorder__oxlang->value );
00475             } else {
00476                 $this->_iOrderLang = oxLang::getInstance()->getBaseLanguage();
00477             }
00478         }
00479         return $this->_iOrderLang;
00480     }
00481 
00489     protected function _setUser( $oUser )
00490     {
00491 
00492         $this->oxorder__oxuserid        = new oxField($oUser->getId());
00493 
00494         // bill address
00495         $this->oxorder__oxbillcompany     = clone $oUser->oxuser__oxcompany;
00496         $this->oxorder__oxbillemail       = clone $oUser->oxuser__oxusername;
00497         $this->oxorder__oxbillfname       = clone $oUser->oxuser__oxfname;
00498         $this->oxorder__oxbilllname       = clone $oUser->oxuser__oxlname;
00499         $this->oxorder__oxbillstreet      = clone $oUser->oxuser__oxstreet;
00500         $this->oxorder__oxbillstreetnr    = clone $oUser->oxuser__oxstreetnr;
00501         $this->oxorder__oxbilladdinfo     = clone $oUser->oxuser__oxaddinfo;
00502         $this->oxorder__oxbillustid       = clone $oUser->oxuser__oxustid;
00503         $this->oxorder__oxbillcity        = clone $oUser->oxuser__oxcity;
00504         $this->oxorder__oxbillcountryid   = clone $oUser->oxuser__oxcountryid;
00505         $this->oxorder__oxbillzip         = clone $oUser->oxuser__oxzip;
00506         $this->oxorder__oxbillfon         = clone $oUser->oxuser__oxfon;
00507         $this->oxorder__oxbillfax         = clone $oUser->oxuser__oxfax;
00508         $this->oxorder__oxbillsal         = clone $oUser->oxuser__oxsal;
00509 
00510 
00511         // delivery address
00512         if ( ( $oDelAdress = $this->getDelAddressInfo() ) ) {
00513             // set delivery address
00514             $this->oxorder__oxdelcompany   = clone $oDelAdress->oxaddress__oxcompany;
00515             $this->oxorder__oxdelfname     = clone $oDelAdress->oxaddress__oxfname;
00516             $this->oxorder__oxdellname     = clone $oDelAdress->oxaddress__oxlname;
00517             $this->oxorder__oxdelstreet    = clone $oDelAdress->oxaddress__oxstreet;
00518             $this->oxorder__oxdelstreetnr  = clone $oDelAdress->oxaddress__oxstreetnr;
00519             $this->oxorder__oxdeladdinfo   = clone $oDelAdress->oxaddress__oxaddinfo;
00520             $this->oxorder__oxdelcity      = clone $oDelAdress->oxaddress__oxcity;
00521             $this->oxorder__oxdelcountryid = clone $oDelAdress->oxaddress__oxcountryid;
00522             $this->oxorder__oxdelzip       = clone $oDelAdress->oxaddress__oxzip;
00523             $this->oxorder__oxdelfon       = clone $oDelAdress->oxaddress__oxfon;
00524             $this->oxorder__oxdelfax       = clone $oDelAdress->oxaddress__oxfax;
00525             $this->oxorder__oxdelsal       = clone $oDelAdress->oxaddress__oxsal;
00526         }
00527     }
00528 
00536     protected function _setWrapping( oxBasket $oBasket )
00537     {
00538         $myConfig = $this->getConfig();
00539 
00540         // wrapping price
00541         if ( ( $oWrappingCost = $oBasket->getCosts( 'oxwrapping' ) ) ) {
00542             $this->oxorder__oxwrapcost = new oxField($oWrappingCost->getBruttoPrice(), oxField::T_RAW);
00543 
00544             // wrapping VAT
00545             if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
00546                 $this->oxorder__oxwrapvat = new oxField($oWrappingCost->getVAT(), oxField::T_RAW);
00547             }
00548         }
00549 
00550         // greetings card
00551         $this->oxorder__oxcardid = new oxField($oBasket->getCardId(), oxField::T_RAW);
00552 
00553         // card text will be stored in database
00554         $this->oxorder__oxcardtext = new oxField($oBasket->getCardMessage(), oxField::T_RAW);
00555     }
00556 
00565     protected function _setOrderArticles( $aArticleList )
00566     {
00567         // reset articles list
00568         $this->_oArticles = oxNew( 'oxlist' );
00569         $iCurrLang = $this->getOrderLanguage();
00570 
00571         // add all the products we have on basket to the order
00572         foreach ( $aArticleList as $oContent ) {
00573 
00574             //$oContent->oProduct = $oContent->getArticle();
00575             $oProduct = $oContent->getArticle();
00576 
00577             // if order language doe not match product language - article must be reloaded in order language
00578             if ( $iCurrLang != $oProduct->getLanguage() ) {
00579                 $oProduct->loadInLang( $iCurrLang, $oProduct->getId() );
00580             }
00581 
00582             $aSelList = array();
00583             // set chosen selectlist
00584             $sSelList = '';
00585             if ( count($oContent->getChosenSelList()) ) {
00586                 foreach ( $oContent->getChosenSelList() as $oItem ) {
00587                     $aSelList[] = $oItem->name.' : '.$oItem->value;
00588                 }
00589                 $sSelList = implode( ', ', $aSelList );
00590             }
00591 
00592             $oOrderArticle = oxNew( 'oxorderarticle' );
00593 
00594             // copying additional data
00595             $oOrderArticle->copyThis( $oProduct );
00596 
00597             // ids, titles, numbers ...
00598             //$oOrderArticle->oxorderarticles__oxid->setValue($oOrderArticle->setId());
00599             $oOrderArticle->setId();
00600             $oOrderArticle->oxorderarticles__oxorderid = new oxField($this->getId());
00601             $oOrderArticle->oxorderarticles__oxartid   = new oxField($oContent->getProductId());
00602             $oOrderArticle->oxorderarticles__oxamount  = new oxField($oContent->getAmount());
00603 
00604             //$oOrderArticle->oxorderarticles__oxartnum->setValue($oContent->oProduct->oxarticles__oxartnum->value);
00605             $oOrderArticle->oxorderarticles__oxartnum  = clone $oProduct->oxarticles__oxartnum;
00606 
00607             //$oOrderArticle->oxorderarticles__oxselvariant->setValue(trim( $sSelList.' '.$oContent->oProduct->oxarticles__oxvarselect->value ));
00608             $oOrderArticle->oxorderarticles__oxselvariant = new oxField(trim( $sSelList.' '.$oProduct->oxarticles__oxvarselect->value ), oxField::T_RAW);
00609 
00610             //$oOrderArticle->oxorderarticles__oxtitle->setValue(trim( $oContent->oProduct->oxarticles__oxtitle->value.' '.$oOrderArticle->oxorderarticles__oxselvariant->value ));
00611             $oOrderArticle->oxorderarticles__oxtitle      = new oxField(trim( $oProduct->oxarticles__oxtitle->value.' '.$oOrderArticle->oxorderarticles__oxselvariant->value ), oxField::T_RAW);
00612 
00613             //$oOrderArticle->oxorderarticles__oxshortdesc->setValue($oContent->oProduct->oxarticles__oxshortdesc->value);
00614             $oOrderArticle->oxorderarticles__oxshortdesc  = new oxField( $oProduct->oxarticles__oxshortdesc->value, oxField::T_RAW);
00615 
00616             // prices
00617             $oOrderArticle->oxorderarticles__oxnetprice  = new oxField($oContent->getPrice()->getNettoPrice(), oxField::T_RAW);
00618             $oOrderArticle->oxorderarticles__oxvatprice  = new oxField($oContent->getPrice()->getVATValue(), oxField::T_RAW);
00619             $oOrderArticle->oxorderarticles__oxbrutprice = new oxField($oContent->getPrice()->getBruttoPrice(), oxField::T_RAW);
00620             $oOrderArticle->oxorderarticles__oxnprice    = new oxField($oContent->getUnitPrice()->getNettoPrice(), oxField::T_RAW);
00621             $oOrderArticle->oxorderarticles__oxbprice    = new oxField($oContent->getUnitPrice()->getBruttoPrice(), oxField::T_RAW);
00622             $oOrderArticle->oxorderarticles__oxvat       = new oxField($oContent->getPrice()->getVAT(), oxField::T_RAW);
00623 
00624             // wrap id
00625             $oOrderArticle->oxorderarticles__oxwrapid      = new oxField($oContent->getWrappingId(), oxField::T_RAW);
00626 
00627             // items shop id
00628             $oOrderArticle->oxorderarticles__oxordershopid = new oxField($oContent->getShopId(), oxField::T_RAW);
00629 
00630             // copying persistent parameters ...
00631             if ( count( $oProduct->getPersParams() ) ) {
00632                 $oOrderArticle->oxorderarticles__oxpersparam = new oxField(serialize( $oProduct->getPersParams() ), oxField::T_RAW);
00633             } elseif ( count( $oContent->getPersParams() ) ) {
00634                 $oOrderArticle->oxorderarticles__oxpersparam = new oxField(serialize( $oContent->getPersParams()), oxField::T_RAW);
00635             }
00636 
00637             // add information for eMail
00638             //P
00639             //TODO: check if this assign is needed at all
00640             $oOrderArticle->oProduct = $oProduct;
00641 
00642             // simulatin order article list
00643             $this->_oArticles->offsetSet( $oOrderArticle->getId(), $oOrderArticle );
00644         }
00645     }
00646 
00658     protected function _executePayment( oxBasket $oBasket, $oUserpayment )
00659     {
00660         $oPayTransaction = $this->_getGateway();
00661         $oPayTransaction->setPaymentParams( $oUserpayment );
00662 
00663         if ( !$oPayTransaction->executePayment( $oBasket->getPrice()->getBruttoPrice(), $this ) ) {
00664             $this->delete();
00665 
00666             // checking for error messages
00667             if ( method_exists( $oPayTransaction, 'getLastError' ) ) {
00668                 if ( ( $sLastError = $oPayTransaction->getLastError() ) ) {
00669                     return $sLastError;
00670                 }
00671             }
00672 
00673             // checking for error codes
00674             if ( method_exists( $oPayTransaction, 'getLastErrorNo' ) ) {
00675                 if ( ( $iLastErrorNo = $oPayTransaction->getLastErrorNo() ) ) {
00676                     return $iLastErrorNo;
00677                 }
00678             }
00679 
00680             return 2; // means no authentication
00681         }
00682         return true; // everything fine
00683     }
00684 
00691     protected function _getGateway()
00692     {
00693         return oxNew( 'oxPaymentGateway' );
00694     }
00695 
00703     protected function _setPayment( $sPaymentid )
00704     {
00705         // copying payment info fields
00706         $aDynvalue = oxSession::getVar( 'dynvalue' );
00707         $aDynvalue = $aDynvalue ? $aDynvalue : oxConfig::getParameter( 'dynvalue' );
00708 
00709         // loading payment object
00710         $oPayment = oxNew( 'oxpayment' );
00711 
00712         if (!$oPayment->load( $sPaymentid )) {
00713             return null;
00714         }
00715 
00716         $oPayment->setDynValues( oxUtils::getInstance()->assignValuesFromText( $oPayment->oxpayments__oxvaldesc->value ) );
00717 
00718         // collecting dynamic values
00719         $aDynVal = array();
00720 
00721         $aPaymentDynValues = $oPayment->getDynValues();
00722         foreach ( $aPaymentDynValues  as $key => $oVal ) {
00723             if ( isset( $aDynvalue[$oVal->name] ) ) {
00724                 $oVal->value = $aDynvalue[$oVal->name];
00725             }
00726 
00727             //$oPayment->setDynValue($key, $oVal);
00728             $aPaymentDynValues[$key] = $oVal;
00729             $aDynVal[$oVal->name] = $oVal->value;
00730         }
00731 
00732         // Store this payment information, we might allow users later to
00733         // reactivate already give payment informations
00734 
00735         $oUserpayment = oxNew( 'oxuserpayment' );
00736         $oUserpayment->oxuserpayments__oxuserid     = clone $this->oxorder__oxuserid;
00737         $oUserpayment->oxuserpayments__oxpaymentsid = new oxField($sPaymentid, oxField::T_RAW);
00738         $oUserpayment->oxuserpayments__oxvalue      = new oxField(oxUtils::getInstance()->assignValuesToText( $aDynVal ), oxField::T_RAW);
00739         $oUserpayment->oxpayments__oxdesc           = clone $oPayment->oxpayments__oxdesc;
00740         $oUserpayment->setDynValues( $aPaymentDynValues );
00741         $oUserpayment->save();
00742 
00743         // storing payment information to order
00744         $this->oxorder__oxpaymentid   = new oxField($oUserpayment->getId(), oxField::T_RAW);
00745         $this->oxorder__oxpaymenttype = clone $oUserpayment->oxuserpayments__oxpaymentsid;
00746 
00747         // returning user payment object which will be used later in code ...
00748         return $oUserpayment;
00749     }
00750 
00760     protected function _updateWishlist( $aArticleList, $oUser )
00761     {
00762 
00763         foreach ( $aArticleList as $oContent) {
00764             if ( ( $sWishId = $oContent->getWishId() ) ) {
00765 
00766                 // checking which wishlist user uses ..
00767                 if ( $sWishId == $oUser->getId() ) {
00768                     $oUserBasket = $oUser->getBasket( 'wishlist' );
00769                 } else {
00770                     $aWhere = array( 'oxuserbaskets.oxuserid' => $sWishId, 'oxuserbaskets.oxtitle' => 'wishlist' );
00771                     $oUserBasket = oxNew( 'oxuserbasket' );
00772                     $oUserBasket->assignRecord( $oUserBasket->buildSelectString( $aWhere ) );
00773                 }
00774 
00775                 // updating users wish list
00776                 if ( $oUserBasket ) {
00777                     if ( !($sProdId = $oContent->getWishArticleId() )) {
00778                         $sProdId = $oContent->getProductId();
00779                     }
00780                     $oUserBasketItem = $oUserBasket->getItem( $sProdId, $oContent->getSelList() );
00781                     $dNewAmount = $oUserBasketItem->oxuserbasketitems__oxamount->value - $oContent->getAmount();
00782                     if ( $dNewAmount < 0) {
00783                         $dNewAmount = 0;
00784                     }
00785                     $oUserBasket->addItemToBasket( $sProdId, $dNewAmount, $oContent->getSelList(), true );
00786                 }
00787             }
00788         }
00789     }
00790 
00800     protected function _updateNoticeList( $aArticleList, $oUser )
00801     {
00802         // loading users notice list ..
00803         if ( $oUserBasket = $oUser->getBasket( 'noticelist' ) ) {
00804             // only if wishlist is enabled
00805             foreach ( $aArticleList as $oContent) {
00806                 $sProdId = $oContent->getProductId();
00807 
00808                 // updating users notice list
00809                 $oUserBasketItem = $oUserBasket->getItem( $sProdId, $oContent->getSelList() );
00810                 $dNewAmount = $oUserBasketItem->oxuserbasketitems__oxamount->value - $oContent->getAmount();
00811                 if ( $dNewAmount < 0) {
00812                     $dNewAmount = 0;
00813                 }
00814                 $oUserBasket->addItemToBasket( $sProdId, $dNewAmount, $oContent->getSelList(), true );
00815             }
00816         }
00817     }
00818 
00824     protected function _updateStock()
00825     {
00826         $myConfig = $this->getConfig();
00827         $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00828 
00829         // ordered articles
00830         $oOrderArticles = $this->getOrderArticles();
00831         if ( $oOrderArticles && count( $oOrderArticles ) > 0 && $blUseStock ) {
00832             foreach ( $oOrderArticles as $oOrderArticle ) {
00833                 $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value * (-1), $myConfig->getConfigParam( 'blAllowNegativeStock' ) );
00834             }
00835         }
00836     }
00837 
00849     protected function _markVouchers( $oBasket, $oUser )
00850     {
00851         $this->_aVoucherList = $oBasket->getVouchers();
00852 
00853         if ( is_array( $this->_aVoucherList ) ) {
00854             foreach ( array_keys( $this->_aVoucherList ) as $sVoucherId ) {
00855                 $oVoucher = oxNew( 'oxvoucher' );
00856                 $oVoucher->load( $sVoucherId );
00857                 $oVoucher->markAsUsed( $this->oxorder__oxid->value, $oUser->oxuser__oxid->value );
00858 
00859                 // -- set deprecated values for email templates
00860                 $oVoucher->oxmodvouchers__oxvouchernr = $oVoucher->oxvouchers__oxvouchernr;
00861                 $oVSerie = $oVoucher->getSerie();
00862                 $oVoucher->oxmodvouchers__oxdiscount     = clone $oVSerie->oxvoucherseries__oxdiscount;
00863                 $oVoucher->oxmodvouchers__oxdiscounttype = clone $oVSerie->oxvoucherseries__oxdiscounttype;
00864                 // -- set deprecated values for email templates
00865 
00866                 $this->_aVoucherList[$sVoucherId] = $oVoucher;
00867             }
00868         }
00869     }
00870 
00876     public function save()
00877     {
00878         if ( ( $blSave = parent::save() ) ) {
00879 
00880             // saving order articles
00881             $oOrderArticles = $this->getOrderArticles();
00882             if ( $oOrderArticles && count( $oOrderArticles ) > 0 ) {
00883                 foreach ( $oOrderArticles as $oOrderArticle ) {
00884                     $oOrderArticle->save();
00885                 }
00886             }
00887         }
00888 
00889         return $blSave;
00890     }
00891 
00898     public function getDelAddressInfo()
00899     {
00900         $oDelAdress = null;
00901         if ( ( $soxAddressId = oxConfig::getParameter( 'deladrid' ) ) ) {
00902             $oDelAdress = oxNew( 'oxbase' );
00903             $oDelAdress->init( 'oxaddress' );
00904             $oDelAdress->load( $soxAddressId );
00905 
00906             //get delivery country name from delivery country id
00907             if ( $oDelAdress->oxaddress__oxcountryid->value && $oDelAdress->oxaddress__oxcountryid->value != -1 ) {
00908                  $oCountry = oxNew( 'oxcountry' );
00909                  $oCountry->load( $oDelAdress->oxaddress__oxcountryid->value );
00910                  $oDelAdress->oxaddress__oxcountry = clone $oCountry->oxcountry__oxtitle;
00911             }
00912         }
00913         return $oDelAdress;
00914     }
00915 
00926     public function validateStock( $oBasket )
00927     {
00928         foreach ( $oBasket->getContents() as $oContent ) {
00929             $oProd = $oContent->getArticle();
00930 
00931             // check if its still available
00932             $iOnStock = $oProd->checkForStock( $oContent->getAmount() );
00933             if ( $iOnStock !== true ) {
00934                 $oEx = oxNew( 'oxOutOfStockException' );
00935                 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00936                 $oEx->setArticleNr( $oProd->oxarticles__oxartnum->value );
00937                 $oEx->setRemainingAmount( $oProd->oxarticles__oxstock->value );
00938                 throw $oEx;
00939             }
00940         }
00941     }
00942 
00948     protected function _insert()
00949     {
00950         $myConfig = $this->getConfig();
00951 
00952         $this->oxorder__oxorderdate = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ), oxField::T_RAW);
00953         $this->oxorder__oxshopid    = new oxField($myConfig->getShopId(), oxField::T_RAW);
00954         $this->oxorder__oxfolder    = new oxField(key( $myConfig->getShopConfVar(  'aOrderfolder', $myConfig->getShopId() ) ), oxField::T_RAW);
00955 
00956         if ( ( $blInsert = parent::_insert() ) ) {
00957             // setting order number
00958             if ( !$this->oxorder__oxordernr->value ) {
00959                 $aWhere = '';
00960                 // separate order numbers for shops ...
00961                 if ( $this->_blSeparateNumbering ) {
00962                     $aWhere = array( 'oxshopid = "'.$myConfig->getShopId().'"' );
00963                 }
00964                 $this->_setRecordNumber( 'oxordernr', $aWhere );
00965             }
00966         }
00967         return $blInsert;
00968     }
00969 
00975     protected function _update()
00976     {
00977         $this->oxorder__oxsenddate = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxorder__oxsenddate->value, true ), oxField::T_RAW);
00978         return parent::_update();
00979     }
00980 
00989     public function delete( $sOxId = null )
00990     {
00991         if ( $sOxId ) {
00992             if ( !$this->load( $sOxId ) ) {
00993                 // such order does not exist
00994                 return false;
00995             }
00996         } elseif ( !$sOxId ) {
00997             $sOxId = $this->getId();
00998         }
00999 
01000         // no order id is passed
01001         if ( !$sOxId ) {
01002             return false;
01003         }
01004 
01005 
01006         // update article stock information and delete order articles
01007         $myConfig   = $this->getConfig();
01008         $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
01009 
01010         $oOrderArticles = $this->getOrderArticles();
01011         foreach ( $oOrderArticles as $oOrderArticle ) {
01012             // updating amounts only on non canceled items
01013             if ( $blUseStock ) {
01014                 if ( !$oOrderArticle->oxorderarticles__oxstorno->value ) {
01015                     $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value, $myConfig->getConfigParam('blAllowNegativeStock') );
01016                 }
01017             }
01018             $oOrderArticle->delete();
01019         }
01020 
01021         // #440 - deleting user payment info
01022         if ( $this->oxorder__oxpaymentid->value ) {
01023             $oDB = oxDb::getDb();
01024             $oDB->execute( 'delete from oxuserpayments where oxuserpayments.oxid = "'.$this->oxorder__oxpaymentid->value.'"' );
01025         }
01026 
01027         return parent::delete( $sOxId );
01028     }
01029 
01040     public function recalculateOrder( $aNewOrderArticles = array(), $blChangeDelivery = false )
01041     {
01042         oxDb::startTransaction();
01043 
01044         try {
01045             // deleting old order with order articles
01046             //load order articles and delete order and order articles
01047             $this->delete();
01048 
01049             $oUser = oxNew( "oxuser" );
01050             $oUser->load( $this->oxorder__oxuserid->value );
01051 
01052             //creating virtual basket and initalizing additional parameters (user, stock, currency)
01053             $oBasket = oxNew( "oxBasket" );
01054 
01055             $aCanceledArticles = array();
01056             $aArticlesIds = array();
01057 
01058             // collect order articles ids's (oxarticles) and canceled order articles
01059             if ( $this->_oArticles = $this->getOrderArticles() ) {
01060                 $this->_oArticles->rewind();
01061                 while ( $oOrderArticle = $this->_oArticles->current() ) {
01062                     $sOrderArticleId = $this->_oArticles->key();
01063 
01064                     //articles id's
01065                     $aArticlesIds[$sOrderArticleId] = $oOrderArticle->oxorderarticles__oxartid->value;
01066 
01067                     // collect canceled order articles, they will not be included in recalculation articles list
01068                     // and will be saved back to order after recalculating and finalizieOrder()
01069                     if ( $oOrderArticle->oxorderarticles__oxstorno->value == '1') {
01070                         $aCanceledArticles[$sOrderArticleId] = $oOrderArticle;
01071 
01072                         // unset canceled article from recalcualtion list
01073                         //unset( $this->_oArticles[$sOrderArticleId] );
01074                         $this->_oArticles->offsetUnset( $sOrderArticleId );
01075                     } else {
01076                         $this->_oArticles->next();
01077                     }
01078                 }
01079             }
01080 
01081             // add or remove newly added order articles to/from old articles list
01082             foreach ($aNewOrderArticles as $oNewOrderArticle) {
01083 
01084                 $sNewOrderArtId = null;
01085                 $blIsOldOrderArticle = false;
01086 
01087                 //check, if added article already is in old order articles list
01088                 if ( ( $sNewOrderArtId = array_search( $oNewOrderArticle->oxorderarticles__oxartid->value, $aArticlesIds ) ) !== false ) {
01089                     $blIsOldOrderArticle = true;
01090                 }
01091 
01092                 //check, if we are going to delete it
01093                 if ( $oNewOrderArticle->oxorderarticles__oxamount->value == 0 ) {
01094                     // if it is in canceled articles list, remove it from canceled articles list,
01095                     // because they will be restored after recalcualtion
01096                     if ( array_key_exists( $sNewOrderArtId, $aCanceledArticles) ) {
01097                         // add it back to recalculation list from canceled articles list
01098                         // to delete it in finalizeOrder()
01099                         $this->_oArticles->offsetSet( $sNewOrderArtId, $aCanceledArticles[$sNewOrderArtId] );
01100                         //$this->_oArticles[$sNewOrderArtId] = $aCanceledArticles[$sNewOrderArtId];
01101 
01102                         // and remove it from canceled articles, because they will be restored after recalculation
01103                         unset($aCanceledArticles[$sNewOrderArtId]);
01104                     }
01105                 }
01106 
01107                 if ( $blIsOldOrderArticle ) {
01108                     //just update existing order article amount
01109                     $this->_oArticles->offsetGet( $sNewOrderArtId )->oxorderarticles__oxamount = clone $oNewOrderArticle->oxorderarticles__oxamount;
01110                     //$this->_oArticles[$sNewOrderArtId]->oxorderarticles__oxamount = clone $oNewOrderArticle->oxorderarticles__oxamount;
01111                 } else {
01112                     //add new article to order articles
01113                     $this->_oArticles->offsetSet( $oNewOrderArticle->getId(), $oNewOrderArticle );
01114                     //$this->_oArticles[] = $oNewOrderArticle;
01115                 }
01116             }
01117 
01118             // add this order articles to virtual basket and recalculates basket
01119             $oBasket = $this->_addOrderArticlesToBasket( $oUser, $this->_oArticles, $blChangeDelivery );
01120 
01121             //finalizing order (skipping payment execution, vouchers marking and mail sending)
01122             $iRet = $this->finalizeOrder( $oBasket, $oUser, true );
01123 
01124             //adding back canceled articles
01125             if ( count($aCanceledArticles) > 0 ) {
01126                 foreach($aCanceledArticles as $oCanceledOrderArticle ) {
01127                     $oCanceledOrderArticle->save();
01128                 }
01129             }
01130 
01131             //if finalizing order failed, rollback transaction
01132             if ( $iRet !== 1 ) {
01133                 oxDb::rollbackTransaction();
01134             } else {
01135                 oxDb::commitTransaction();
01136             }
01137 
01138         } catch( Exception $oE ) {
01139                 // if exception, rollBack everything
01140                 oxDb::rollbackTransaction();
01141         }
01142     }
01143 
01151     public function pdfFooter( $oPdf )
01152     {
01153     }
01154 
01162     public function pdfHeaderplus( $oPdf )
01163     {
01164     }
01165 
01173     public function pdfHeader( $oPdf )
01174     {
01175     }
01176 
01185     public function genPdf( $sFilename, $iSelLang = 0 )
01186     {
01187     }
01188 
01194     public function getInvoiceNum()
01195     {
01196         $sQ = 'select max(oxorder.oxinvoicenr) from oxorder where oxorder.oxshopid = "'.$this->getConfig()->getShopId().'" ';
01197         return ( ( int ) oxDb::getDb()->getOne( $sQ ) + 1 );
01198     }
01199 
01200 
01206     public function getShippingSetList()
01207     {
01208         $myConfig = $this->getConfig();
01209 
01210         // in which country we deliver
01211         $sShipID = $this->oxorder__oxdelcountryid->value;
01212 
01213         if (!$sShipID) {
01214             $sShipID = $this->oxorder__oxbillcountryid->value;
01215         }
01216 
01217         $oUser = oxNew( "oxuser" );
01218         $oUser->load( $this->oxorder__oxuserid->value );
01219 
01220         // add this order articles to basket and recalculate basket
01221         $oBasket = $this->_addOrderArticlesToBasket( $oUser, $this->getOrderArticles() );
01222 
01223         $aOrderDelSetList = array();
01224 
01225         // load fitting deliveries list
01226         $oDleliveryList = oxNew( "oxDeliveryList", "core");
01227         $oDleliveryList->setCollectFittingDeliveriesSets( true );
01228         $aOrderDelSetList = $oDleliveryList->getDeliveryList( $oBasket, $oUser, $sShipID, null );
01229 
01230         return $aOrderDelSetList;
01231     }
01232 
01238     public function getVoucherNrList()
01239     {
01240         $oDB = oxDb::getDb( true );
01241         $aVouchers = array();
01242         $sSelect =  "select oxvouchernr from oxvouchers where oxorderid = '".$this->oxorder__oxid->value."'";
01243         $rs = $oDB->execute( $sSelect);
01244         if ($rs != false && $rs->recordCount() > 0) {
01245             while (!$rs->EOF) {
01246                 $aVouchers[] = $rs->fields['oxvouchernr'];
01247                 $rs->moveNext();
01248             }
01249         }
01250         return $aVouchers;
01251     }
01252 
01260     public function getOrderSum( $blToday = false )
01261     {
01262         $sSelect  = 'select sum(oxtotalordersum / oxcurrate) from oxorder where ';
01263         $sSelect .= 'oxshopid = "'.$this->getConfig()->getShopId().'" and oxorder.oxstorno != "1" ';
01264 
01265         if ( $blToday ) {
01266             $sSelect .= 'and oxorderdate like "'.date( 'Y-m-d').'%" ';
01267         }
01268 
01269         return ( double ) oxDb::getDb()->getOne( $sSelect );
01270     }
01271 
01279     public function getOrderCnt( $blToday = false )
01280     {
01281         $sSelect  = 'select count(*) from oxorder where ';
01282         $sSelect .= 'oxshopid = "'.$this->getConfig()->getShopId().'"  and oxorder.oxstorno != "1" ';
01283 
01284         if ( $blToday ) {
01285             $sSelect .= 'and oxorderdate like "'.date( 'Y-m-d').'%" ';
01286         }
01287 
01288         return ( int ) oxDb::getDb()->getOne( $sSelect );
01289     }
01290 
01291 
01299     protected function _checkOrderExist( $sOxId = null )
01300     {
01301         if ( !$sOxId) {
01302             return false;
01303         }
01304 
01305         if ( oxDb::getDb()->getOne( 'select oxid from oxorder where oxid = "'.$sOxId.'"' ) ) {
01306             return true;
01307         }
01308 
01309         return false;
01310     }
01311 
01321     protected function _sendOrderByEmail( $oUser = null, $oBasket = null, $oPayment = null )
01322     {
01323         $iRet = 0;
01324 
01325         // add user, basket and payment to order
01326         $this->_oUser    = $oUser;
01327         $this->_oBasket  = $oBasket;
01328         $this->_oPayment = $oPayment;
01329 
01330         $oxEmail = oxNew( 'oxemail' );
01331 
01332         // send order email to user
01333         if ( $oxEmail->sendOrderEMailToUser( $this ) ) {
01334             // mail to user was successfully sent
01335             $iRet = 1;
01336         }
01337 
01338         // send order email to shop owner
01339         $oxEmail->sendOrderEMailToOwner( $this );
01340 
01341         return $iRet;
01342     }
01343 
01349     public function getUser()
01350     {
01351         return $this->_oUser;
01352     }
01353 
01359     public function getBasket()
01360     {
01361         return $this->_oBasket;
01362     }
01363 
01369     public function getPayment()
01370     {
01371         return $this->_oPayment;
01372     }
01373 
01379     public function getVoucherList()
01380     {
01381         return $this->_aVoucherList;
01382     }
01383 
01389     public function getDelSet()
01390     {
01391         if ( $this->_oDelSet == null ) {
01392             // load deliveryset info
01393             $this->_oDelSet = oxNew( 'oxdeliveryset' );
01394             $this->_oDelSet->load( $this->oxorder__oxdeltype->value );
01395         }
01396 
01397         return $this->_oDelSet;
01398     }
01399 
01405     public function getPaymentType()
01406     {
01407         if ( $this->oxorder__oxpaymentid->value && $this->_oPaymentType == null ) {
01408             $this->_oPaymentType = oxNew( 'oxuserpayment' );
01409             $this->_oPaymentType->load( $this->oxorder__oxpaymentid->value );
01410         }
01411 
01412         return $this->_oPaymentType;
01413     }
01414 
01420     public function getGiftCard()
01421     {
01422         if ( $this->oxorder__oxcardid->value && $this->_oGiftCard == null ) {
01423             $this->_oGiftCard = oxNew( 'oxwrapping' );
01424             $this->_oGiftCard->load( $this->oxorder__oxcardid->value );
01425         }
01426 
01427         return $this->_oGiftCard;
01428     }
01429 
01437     public function setSeparateNumbering( $blSeparateNumbering = null )
01438     {
01439         $this->_blSeparateNumbering = $blSeparateNumbering;
01440     }
01441 
01449     public function getLastUserPaymentType( $sUserId)
01450     {
01451         $sQ = 'select oxorder.oxpaymenttype from oxorder where oxorder.oxshopid="'.$this->getConfig()->getShopId().'" and oxorder.oxuserid="'.$sUserId.'" order by oxorder.oxorderdate desc ';
01452         $sLastPaymentId = oxDb::getDb()->getOne( $sQ );
01453         return $sLastPaymentId;
01454     }
01455 
01466     protected function _makeSelListArray( $sArtId = null, $sOrderArtSelList = null )
01467     {
01468         $aList = array();
01469         $aRet  = array();
01470 
01471         if ( $sArtId ) {
01472             $aList = explode( ",", $sOrderArtSelList );
01473 
01474             //$oArticle = oxNew( "oxArticle", "core" );
01475             $oArticle = oxNew( "oxArticle" );
01476             $oArticle->load( $sArtId );
01477             $aArticleSelList = $oArticle->getSelectLists();
01478 
01479             //formating temporary list array from string
01480             foreach ( $aList as $sList ) {
01481                 if ( $sList ) {
01482 
01483                     $aVal = explode( ":", $sList );
01484 
01485                     if ( isset($aVal[0]) && isset($aVal[1])) {
01486                         $sOrderArtListTitle = strtolower( trim($aVal[0]) );
01487                         $sOrderArtSelValue  = strtolower( trim($aVal[1]) );
01488 
01489                         //checking article list for matches with article list stored in oxorderitem
01490                         $iSelListNum = 0;
01491                         if ( count($aArticleSelList) > 0 ) {
01492                             foreach ( $aArticleSelList as $aSelect ) {
01493                                 //chek if selects titles are equal
01494 
01495                                 if ( strtolower($aSelect['name']) == $sOrderArtListTitle ) {
01496                                     //try to find matching select items value
01497                                     $iSelValueNum = 0;
01498                                     foreach ( $aSelect as $oSel ) {
01499                                         if ( strtolower($oSel->name) == $sOrderArtSelValue ) {
01500                                             // found, adding tu return array
01501                                             $aRet[$iSelListNum] = $iSelValueNum;
01502                                         }
01503                                         //next article list item
01504                                         $iSelValueNum++;
01505                                     }
01506                                 }
01507                                 //next article list
01508                                 $iSelListNum++;
01509                             }
01510                         }
01511                     }
01512                 }
01513             }
01514         }
01515 
01516         return $aRet;
01517     }
01518 
01528     protected function _addOrderArticlesToBasket( $oUser = null, $aOrderArticles = null, $blChangeDelivery = false )
01529     {
01530         $myConfig = $this->getConfig();
01531 
01532         $oBasket = oxNew( "oxbasket" );
01533 
01534         // setting virtual basket user
01535         $oBasket->setBasketUser( $oUser );
01536 
01537         // setting basket currency order uses
01538         $aCurrencies = $myConfig->getCurrencyArray();
01539         foreach ($aCurrencies as $oCur) {
01540             if ($oCur->name == $this->oxorder__oxcurrency->value) {
01541                 $oBasketCur = $oCur;
01542                 break;
01543             }
01544         }
01545 
01546         $oBasket->setBasketCurrency( $oBasketCur );
01547 
01548         // if no order articles, return empty basket
01549         if (count($aOrderArticles) < 1) {
01550             return $oBasket;
01551         }
01552 
01553         //adding order articles to basket
01554         foreach ( $aOrderArticles as $oOrderArticle ) {
01555             $sArtId      = $oOrderArticle->oxorderarticles__oxartid->value;
01556             $dAmount     = $oOrderArticle->oxorderarticles__oxamount->value;
01557             $sSelVariant = $oOrderArticle->oxorderarticles__oxselvariant->value;
01558 
01559             if ( $oOrderArticle->oxorderarticles__oxpersparam->value ) {
01560                 $aPersParam = unserialize($oOrderArticle->oxorderarticles__oxpersparam->value);
01561             } else {
01562                 $aPersParam = null;
01563             }
01564 
01565             $aSel = $this->_makeSelListArray( $sArtId, $sSelVariant );
01566 
01567             $oBasketItem = $oBasket->addToBasket( $sArtId, $dAmount, $aSel, $aPersParam );
01568             if ( $oBasketItem ) {
01569                 $oBasketItem->setWrapping( $oOrderArticle->oxorderarticles__oxwrapid->value );
01570             }
01571         }
01572 
01573         // set basket card id and message
01574         $oBasket->setCardId( $this->oxorder__oxcardid->value );
01575         $oBasket->setCardMessage( $this->oxorder__oxcardtext->value );
01576 
01577         // set skip vouchers availability checking
01578         $oBasket->setSkipVouchersChecking( true );
01579 
01580         // add previously used vouchers
01581         $sQ = 'select oxid from oxvouchers where oxorderid = "'.$this->getId().'"';
01582         $aVouchers = oxDb::getDb( true )->getAll( $sQ );
01583         foreach ( $aVouchers AS $aVoucher ) {
01584             $oBasket->addVoucher($aVoucher['oxid']);
01585         }
01586 
01587         //set shipping
01588         $oBasket->setShipping( $this->oxorder__oxdeltype->value );
01589         //V #M429: Shipping and total prices were not calculated correct 
01590         //when user changed delivery costs in admin 
01591         if ( $blChangeDelivery ) {
01592             $oBasket->setDeliveryPrice( $this->getOrderDeliveryPrice() );
01593         }
01594         //set basket payment
01595         $oBasket->setPayment( $this->oxorder__oxpaymenttype->value );
01596 
01597         // recalculating basket
01598         $oBasket->calculateBasket( true );
01599 
01600         return $oBasket;
01601     }
01602 
01610     protected function _setDeprecatedValues()
01611     {
01612         if ( $this->oxorder__oxstorno->value != 1 ) {
01613             $oCur = $this->getConfig()->getActShopCurrencyObject();
01614 
01615             $this->totalnetsum   = $this->oxorder__oxtotalnetsum->value;
01616             $this->totalbrutsum  = $this->oxorder__oxtotalbrutsum->value;
01617             $this->totalorder    = $this->oxorder__oxtotalordersum->value;
01618             $this->ftotalnetsum  = oxLang::getInstance()->formatCurrency( $this->oxorder__oxtotalnetsum->value, $oCur );
01619             $this->ftotalbrutsum = oxLang::getInstance()->formatCurrency( $this->oxorder__oxtotalbrutsum->value, $oCur );
01620             $this->fdelcost      = oxLang::getInstance()->formatCurrency( $this->oxorder__oxdelcost->value, $oCur );
01621             $this->fpaycost      = oxLang::getInstance()->formatCurrency( $this->oxorder__oxpaycost->value, $oCur );
01622             $this->fwrapcost     = oxLang::getInstance()->formatCurrency( $this->oxorder__oxwrapcost->value, $oCur );
01623             $this->ftotalorder   = $this->getTotalOrderSum();
01624             $this->totalvouchers = 0;
01625 
01626             if ( $this->oxorder__oxvoucherdiscount->value ) {
01627                 $this->totalvouchers  = oxLang::getInstance()->formatCurrency( $this->oxorder__oxvoucherdiscount->value, $oCur );
01628             }
01629 
01630             if ( $this->oxorder__oxdiscount->value ) {
01631                 $this->discount  = $this->oxorder__oxdiscount->value;
01632                 $this->fdiscount = oxLang::getInstance()->formatCurrency( $this->oxorder__oxdiscount->value, $oCur );
01633             }
01634         }
01635     }
01636 
01642     public function getTotalOrderSum()
01643     {
01644         $oCur = $this->getConfig()->getActShopCurrencyObject();
01645         return oxLang::getInstance()->formatCurrency( $this->oxorder__oxtotalordersum->value, $oCur );
01646     }
01647 
01648 }

Generated on Fri Dec 19 14:20:29 2008 for OXID eShop CE by  doxygen 1.5.5