oxorder.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxOrder extends oxBase
00008 {
00009 
00015     protected $_aSkipSaveFields = array( 'oxorderdate' );
00016 
00022     protected $_oArticles = null;
00023 
00029     protected $_oDelSet   = null;
00030 
00036     protected $_oGiftCard = null;
00037 
00043     protected $_oPaymentType = null;
00044 
00050     protected $_oPayment = null;
00051 
00057     protected $_aVoucherList = null;
00058 
00064     protected $_oDelPrice = null;
00065 
00071     protected $_oUser = null;
00072 
00078     protected $_oBasket = null;
00079 
00085     protected $_oWrappingPrice = null;
00086 
00092     protected $_oPaymentPrice = null;
00093 
00099     protected $_sClassName = 'oxorder';
00100 
00106     protected $_blSeparateNumbering = null;
00107 
00113     protected $_iOrderLang = null;
00114 
00118     public function __construct()
00119     {
00120         parent::__construct();
00121         $this->init( 'oxorder' );
00122 
00123         // set usage of seperate orders numbering for different shops
00124         $this->setSeparateNumbering( $this->getConfig()->getConfigParam( 'blSeparateNumbering') );
00125 
00126     }
00127 
00135     public function __get( $sName )
00136     {
00137         if ( $sName == 'oDelSet' ) {
00138             return $this->getDelSet();
00139         }
00140 
00141         if ( $sName == 'oxorder__oxbillcountry' ) {
00142             return $this->getBillCountry();
00143         }
00144 
00145         if ( $sName == 'oxorder__oxdelcountry' ) {
00146             return $this->getDelCountry();
00147         }
00148     }
00149 
00157     public function assign( $dbRecord )
00158     {
00159 
00160         parent::assign( $dbRecord );
00161 
00162         $oUtilsDate = oxUtilsDate::getInstance();
00163 
00164         // convert date's to international format
00165         $this->oxorder__oxorderdate = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxorderdate->value));
00166         $this->oxorder__oxsenddate  = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxsenddate->value));
00167 
00168         //settting deprecated template variables
00169         $this->_setDeprecatedValues();
00170     }
00171 
00179     protected function _getCountryTitle( $sCountryId )
00180     {
00181         $sTitle = null;
00182         if ( $sCountryId && $sCountryId != '-1' ) {
00183             $oCountry = oxNew( 'oxcountry' );
00184             $oCountry->load( $sCountryId );
00185             $sTitle = $oCountry->oxcountry__oxtitle->value;
00186         }
00187 
00188         return $sTitle;
00189     }
00190 
00196     public function getOrderArticles()
00197     {
00198         if ( $this->_oArticles == null ) {
00199 
00200             // order articles
00201             $this->_oArticles = oxNew( 'oxlist' );
00202             $this->_oArticles->init( 'oxorderarticle' );
00203 
00204             $sSelect = 'select oxorderarticles.* from oxorderarticles
00205                         where oxorderarticles.oxorderid="'.$this->getId().'"
00206                         order by oxorderarticles.oxartid';
00207             $this->_oArticles->selectString( $sSelect );
00208         }
00209 
00210         return $this->_oArticles;
00211     }
00212 
00218     public function getOrderDeliveryPrice()
00219     {
00220         if ( $this->_oDelPrice != null ) {
00221             return $this->_oDelPrice;
00222         }
00223 
00224         $this->_oDelPrice = oxNew( 'oxprice' );
00225         $this->_oDelPrice->setBruttoPriceMode();
00226         $this->_oDelPrice->setPrice( $this->oxorder__oxdelcost->value, $this->oxorder__oxdelvat->value );
00227         return $this->_oDelPrice;
00228     }
00229 
00235     public function getOrderWrappingPrice()
00236     {
00237         if ( $this->_oWrappingPrice != null ) {
00238             return $this->_oWrappingPrice;
00239         }
00240 
00241         $this->_oWrappingPrice = oxNew( 'oxprice' );
00242         $this->_oWrappingPrice->setBruttoPriceMode();
00243         $this->_oWrappingPrice->setPrice( $this->oxorder__oxwrapcost->value, $this->oxorder__oxwrapvat->value );
00244         return $this->_oWrappingPrice;
00245     }
00246 
00252     public function getOrderPaymentPrice()
00253     {
00254         if ( $this->_oPaymentPrice != null ) {
00255             return $this->_oPaymentPrice;
00256         }
00257 
00258         $this->_oPaymentPrice = oxNew( 'oxprice' );
00259         $this->_oPaymentPrice->setBruttoPriceMode();
00260         $this->_oPaymentPrice->setPrice( $this->oxorder__oxpaycost->value, $this->oxorder__oxpayvat->value );
00261         return $this->_oPaymentPrice;
00262     }
00263 
00270     public function getOrderNetSum()
00271     {
00272         $dTotalNetSum = 0;
00273 
00274         $dTotalNetSum += $this->oxorder__oxtotalnetsum->value;
00275         $dTotalNetSum += $this->getOrderDeliveryPrice()->getNettoPrice();
00276         $dTotalNetSum += $this->getOrderWrappingPrice()->getNettoPrice();
00277         $dTotalNetSum += $this->getOrderPaymentPrice()->getNettoPrice();
00278 
00279         return $dTotalNetSum;
00280     }
00281 
00302     public function finalizeOrder( oxBasket $oBasket, $oUser, $blRecalculatingOrder = false )
00303     {
00304         // check if this order is already stored
00305         $sGetChallenge = oxSession::getVar( 'sess_challenge' );
00306         if ( $this->_checkOrderExist( $sGetChallenge ) ) {
00307             oxUtils::getInstance()->logger( 'BLOCKER' );
00308             // we might use this later, this means that somebody klicked like mad on order button
00309             return 3;
00310         }
00311 
00312         // if not recalculating order, use sess_challenge id, else leave old order id
00313         if ( !$blRecalculatingOrder ) {
00314             // use this ID
00315             $this->setId( $sGetChallenge );
00316         }
00317 
00318         // copies user info
00319         $this->_setUser( $oUser );
00320 
00321         // copies basket info
00322         $this->_loadFromBasket( $oBasket );
00323 
00324         // payment information
00325         $oUserPayment = $this->_setPayment( $oBasket->getPaymentId() );
00326 
00327         // set folder information, if order is new
00328         // #M575 in recalcualting order case folder must be the same as it was
00329         if ( !$blRecalculatingOrder ) {
00330             $this->_setFolder();
00331         }
00332 
00333         //saving all order data to DB
00334         $this->save();
00335 
00336         // executing payment (on failure deletes order and returns error code)
00337         // in case when recalcualting order, payment execution is skipped
00338         if ( !$blRecalculatingOrder ) {
00339             $blRet = $this->_executePayment( $oBasket, $oUserPayment );
00340             if ( $blRet !== true ) {
00341                 return $blRet;
00342             }
00343         }
00344 
00345         // deleting remark info only when order is finished
00346         oxSession::deleteVar( 'ordrem' );
00347 
00348         // updating order trans status (success status)
00349         $this->_setOrderStatus( 'OK' );
00350 
00351         // store orderid
00352         $oBasket->setOrderId( $this->getId() );
00353 
00354         // updating bought items stock
00355         $this->_updateStock();
00356 
00357         // updating wish lists
00358         $this->_updateWishlist( $oBasket->getContents(), $oUser );
00359 
00360         // updating users notice list
00361         $this->_updateNoticeList( $oBasket->getContents(), $oUser );
00362 
00363         // marking vouchers as used and sets them to $this->_aVoucherList (will be used in order email)
00364         // skipping this action in case of order recalculation
00365         if ( !$blRecalculatingOrder ) {
00366             $this->_markVouchers( $oBasket, $oUser );
00367         }
00368 
00369         // send order by email to shop owner and current user
00370         // skipping this action in case of order recalculation
00371         if ( !$blRecalculatingOrder ) {
00372             $iRet = $this->_sendOrderByEmail( $oUser, $oBasket, $oUserPayment );
00373         } else {
00374             $iRet = 1;
00375         }
00376 
00377         return $iRet;
00378     }
00379 
00387     protected function _setOrderStatus( $sStatus )
00388     {
00389         $sQ = 'update oxorder set oxtransstatus="'.$sStatus.'" where oxid="'.$this->getId().'" ';
00390         oxDb::getDb()->execute( $sQ );
00391     }
00392 
00403     protected function _loadFromBasket( oxBasket $oBasket )
00404     {
00405         $myConfig = $this->getConfig();
00406 
00407         // store IP Adress - default must be FALSE as it is illegal to store
00408         if ( $myConfig->getConfigParam( 'blStoreIPs' ) &&  $this->oxorder__oxip->value === null ) {
00409             $this->oxorder__oxip = new oxField(oxUtilsServer::getInstance()->getRemoteAddress(), oxField::T_RAW);
00410         }
00411 
00412         // copying main price info
00413         $this->oxorder__oxtotalnetsum   = new oxField(oxUtils::getInstance()->fRound($oBasket->getProductsPrice()->getNettoSum()), oxField::T_RAW);
00414         $this->oxorder__oxtotalbrutsum  = new oxField($oBasket->getProductsPrice()->getBruttoSum(), oxField::T_RAW);
00415         $this->oxorder__oxtotalordersum = new oxField($oBasket->getPrice()->getBruttoPrice(), oxField::T_RAW);
00416 
00417         // payment costs if available
00418         if ( ( $oPaymentCost = $oBasket->getCosts( 'oxpayment' ) ) ) {
00419             $this->oxorder__oxpaycost = new oxField($oPaymentCost->getBruttoPrice(), oxField::T_RAW);
00420             $this->oxorder__oxpayvat  = new oxField($oPaymentCost->getVAT(), oxField::T_RAW);
00421         }
00422 
00423         // delivery info
00424         if ( ( $oDeliveryCost = $oBasket->getCosts( 'oxdelivery' ) ) ) {
00425             $this->oxorder__oxdelcost = new oxField($oDeliveryCost->getBruttoPrice(), oxField::T_RAW);
00426             //V #M382: Save VAT, not VAT value for delivery costs
00427             $this->oxorder__oxdelvat  = new oxField($oDeliveryCost->getVAT(), oxField::T_RAW); //V #M382
00428             $this->oxorder__oxdeltype = new oxField($oBasket->getShippingId(), oxField::T_RAW);
00429         }
00430 
00431         // user remark
00432         if ( $this->oxorder__oxremark->value === null ) {
00433             $this->oxorder__oxremark = new oxField(oxSession::getVar( 'ordrem' ), oxField::T_RAW);
00434         }
00435 
00436         // currency
00437         $oCur = $myConfig->getActShopCurrencyObject();
00438         $this->oxorder__oxcurrency = new oxField($oCur->name);
00439         $this->oxorder__oxcurrate  = new oxField($oCur->rate, oxField::T_RAW);
00440 
00441         // store voucherdiscount
00442         if ( ( $oVoucherDiscount = $oBasket->getVoucherDiscount() ) ) {
00443             $this->oxorder__oxvoucherdiscount = new oxField($oVoucherDiscount->getBruttoPrice(), oxField::T_RAW);
00444         }
00445 
00446         // general discount
00447         $dDiscount = 0;
00448         $aDiscounts = $oBasket->getDiscounts();
00449         if ( count($aDiscounts) > 0 ) {
00450             foreach ($aDiscounts as $oDiscount) {
00451                 $dDiscount += $oDiscount->dDiscount;
00452             }
00453         }
00454         if ( $dDiscount ) {
00455             $this->oxorder__oxdiscount = new oxField($dDiscount, oxField::T_RAW);
00456         }
00457 
00458         //order language
00459         $this->oxorder__oxlang = new oxField( $this->getOrderLanguage() );
00460 
00461 
00462         // initial status - 'ERROR'
00463         $this->oxorder__oxtransstatus = new oxField('ERROR', oxField::T_RAW);
00464 
00465         // copies basket product info ...
00466         $this->_setOrderArticles( $oBasket->getContents() );
00467 
00468         // copies wrapping info
00469         $this->_setWrapping( $oBasket );
00470     }
00471 
00478     public function getOrderLanguage()
00479     {
00480         if ( $this->_iOrderLang === null ) {
00481             if ( isset( $this->oxorder__oxlang->value ) ) {
00482                 $this->_iOrderLang = oxLang::getInstance()->validateLanguage( $this->oxorder__oxlang->value );
00483             } else {
00484                 $this->_iOrderLang = oxLang::getInstance()->getBaseLanguage();
00485             }
00486         }
00487         return $this->_iOrderLang;
00488     }
00489 
00497     protected function _setUser( $oUser )
00498     {
00499 
00500         $this->oxorder__oxuserid        = new oxField($oUser->getId());
00501 
00502         // bill address
00503         $this->oxorder__oxbillcompany     = clone $oUser->oxuser__oxcompany;
00504         $this->oxorder__oxbillemail       = clone $oUser->oxuser__oxusername;
00505         $this->oxorder__oxbillfname       = clone $oUser->oxuser__oxfname;
00506         $this->oxorder__oxbilllname       = clone $oUser->oxuser__oxlname;
00507         $this->oxorder__oxbillstreet      = clone $oUser->oxuser__oxstreet;
00508         $this->oxorder__oxbillstreetnr    = clone $oUser->oxuser__oxstreetnr;
00509         $this->oxorder__oxbilladdinfo     = clone $oUser->oxuser__oxaddinfo;
00510         $this->oxorder__oxbillustid       = clone $oUser->oxuser__oxustid;
00511         $this->oxorder__oxbillcity        = clone $oUser->oxuser__oxcity;
00512         $this->oxorder__oxbillcountryid   = clone $oUser->oxuser__oxcountryid;
00513         $this->oxorder__oxbillzip         = clone $oUser->oxuser__oxzip;
00514         $this->oxorder__oxbillfon         = clone $oUser->oxuser__oxfon;
00515         $this->oxorder__oxbillfax         = clone $oUser->oxuser__oxfax;
00516         $this->oxorder__oxbillsal         = clone $oUser->oxuser__oxsal;
00517 
00518 
00519         // delivery address
00520         if ( ( $oDelAdress = $this->getDelAddressInfo() ) ) {
00521             // set delivery address
00522             $this->oxorder__oxdelcompany   = clone $oDelAdress->oxaddress__oxcompany;
00523             $this->oxorder__oxdelfname     = clone $oDelAdress->oxaddress__oxfname;
00524             $this->oxorder__oxdellname     = clone $oDelAdress->oxaddress__oxlname;
00525             $this->oxorder__oxdelstreet    = clone $oDelAdress->oxaddress__oxstreet;
00526             $this->oxorder__oxdelstreetnr  = clone $oDelAdress->oxaddress__oxstreetnr;
00527             $this->oxorder__oxdeladdinfo   = clone $oDelAdress->oxaddress__oxaddinfo;
00528             $this->oxorder__oxdelcity      = clone $oDelAdress->oxaddress__oxcity;
00529             $this->oxorder__oxdelcountryid = clone $oDelAdress->oxaddress__oxcountryid;
00530             $this->oxorder__oxdelzip       = clone $oDelAdress->oxaddress__oxzip;
00531             $this->oxorder__oxdelfon       = clone $oDelAdress->oxaddress__oxfon;
00532             $this->oxorder__oxdelfax       = clone $oDelAdress->oxaddress__oxfax;
00533             $this->oxorder__oxdelsal       = clone $oDelAdress->oxaddress__oxsal;
00534         }
00535     }
00536 
00544     protected function _setWrapping( oxBasket $oBasket )
00545     {
00546         $myConfig = $this->getConfig();
00547 
00548         // wrapping price
00549         if ( ( $oWrappingCost = $oBasket->getCosts( 'oxwrapping' ) ) ) {
00550             $this->oxorder__oxwrapcost = new oxField($oWrappingCost->getBruttoPrice(), oxField::T_RAW);
00551 
00552             // wrapping VAT
00553             if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
00554                 $this->oxorder__oxwrapvat = new oxField($oWrappingCost->getVAT(), oxField::T_RAW);
00555             }
00556         }
00557 
00558         // greetings card
00559         $this->oxorder__oxcardid = new oxField($oBasket->getCardId(), oxField::T_RAW);
00560 
00561         // card text will be stored in database
00562         $this->oxorder__oxcardtext = new oxField($oBasket->getCardMessage(), oxField::T_RAW);
00563     }
00564 
00573     protected function _setOrderArticles( $aArticleList )
00574     {
00575         // reset articles list
00576         $this->_oArticles = oxNew( 'oxlist' );
00577         $iCurrLang = $this->getOrderLanguage();
00578 
00579         // add all the products we have on basket to the order
00580         foreach ( $aArticleList as $oContent ) {
00581 
00582             //$oContent->oProduct = $oContent->getArticle();
00583             $oProduct = $oContent->getArticle();
00584 
00585             // if order language doe not match product language - article must be reloaded in order language
00586             if ( $iCurrLang != $oProduct->getLanguage() ) {
00587                 $oProduct->loadInLang( $iCurrLang, $oProduct->getId() );
00588             }
00589 
00590             $aSelList = array();
00591             // set chosen selectlist
00592             $sSelList = '';
00593             if ( count($oContent->getChosenSelList()) ) {
00594                 foreach ( $oContent->getChosenSelList() as $oItem ) {
00595                     $aSelList[] = $oItem->name.' : '.$oItem->value;
00596                 }
00597                 $sSelList = implode( ', ', $aSelList );
00598             }
00599 
00600             $oOrderArticle = oxNew( 'oxorderarticle' );
00601 
00602             // copying additional data
00603             $oOrderArticle->copyThis( $oProduct );
00604 
00605             // ids, titles, numbers ...
00606             //$oOrderArticle->oxorderarticles__oxid->setValue($oOrderArticle->setId());
00607             $oOrderArticle->setId();
00608             $oOrderArticle->oxorderarticles__oxorderid = new oxField($this->getId());
00609             $oOrderArticle->oxorderarticles__oxartid   = new oxField($oContent->getProductId());
00610             $oOrderArticle->oxorderarticles__oxamount  = new oxField($oContent->getAmount());
00611 
00612             //$oOrderArticle->oxorderarticles__oxartnum->setValue($oContent->oProduct->oxarticles__oxartnum->value);
00613             $oOrderArticle->oxorderarticles__oxartnum  = clone $oProduct->oxarticles__oxartnum;
00614 
00615             //$oOrderArticle->oxorderarticles__oxselvariant->setValue(trim( $sSelList.' '.$oContent->oProduct->oxarticles__oxvarselect->value ));
00616             $oOrderArticle->oxorderarticles__oxselvariant = new oxField(trim( $sSelList.' '.$oProduct->oxarticles__oxvarselect->value ), oxField::T_RAW);
00617 
00618             //$oOrderArticle->oxorderarticles__oxtitle->setValue(trim( $oContent->oProduct->oxarticles__oxtitle->value.' '.$oOrderArticle->oxorderarticles__oxselvariant->value ));
00619             $oOrderArticle->oxorderarticles__oxtitle      = new oxField(trim( $oProduct->oxarticles__oxtitle->value.' '.$oOrderArticle->oxorderarticles__oxselvariant->value ), oxField::T_RAW);
00620 
00621             //$oOrderArticle->oxorderarticles__oxshortdesc->setValue($oContent->oProduct->oxarticles__oxshortdesc->value);
00622             $oOrderArticle->oxorderarticles__oxshortdesc  = new oxField( $oProduct->oxarticles__oxshortdesc->value, oxField::T_RAW);
00623 
00624             // prices
00625             $oOrderArticle->oxorderarticles__oxnetprice  = new oxField($oContent->getPrice()->getNettoPrice(), oxField::T_RAW);
00626             $oOrderArticle->oxorderarticles__oxvatprice  = new oxField($oContent->getPrice()->getVATValue(), oxField::T_RAW);
00627             $oOrderArticle->oxorderarticles__oxbrutprice = new oxField($oContent->getPrice()->getBruttoPrice(), oxField::T_RAW);
00628             $oOrderArticle->oxorderarticles__oxnprice    = new oxField($oContent->getUnitPrice()->getNettoPrice(), oxField::T_RAW);
00629             $oOrderArticle->oxorderarticles__oxbprice    = new oxField($oContent->getUnitPrice()->getBruttoPrice(), oxField::T_RAW);
00630             $oOrderArticle->oxorderarticles__oxvat       = new oxField($oContent->getPrice()->getVAT(), oxField::T_RAW);
00631 
00632             // wrap id
00633             $oOrderArticle->oxorderarticles__oxwrapid      = new oxField($oContent->getWrappingId(), oxField::T_RAW);
00634 
00635             // items shop id
00636             $oOrderArticle->oxorderarticles__oxordershopid = new oxField($oContent->getShopId(), oxField::T_RAW);
00637 
00638             // copying persistent parameters ...
00639             if ( count( $oProduct->getPersParams() ) ) {
00640                 $oOrderArticle->oxorderarticles__oxpersparam = new oxField(serialize( $oProduct->getPersParams() ), oxField::T_RAW);
00641             } elseif ( count( $oContent->getPersParams() ) ) {
00642                 $oOrderArticle->oxorderarticles__oxpersparam = new oxField(serialize( $oContent->getPersParams()), oxField::T_RAW);
00643             }
00644 
00645             // add information for eMail
00646             //P
00647             //TODO: check if this assign is needed at all
00648             $oOrderArticle->oProduct = $oProduct;
00649 
00650             // simulatin order article list
00651             $this->_oArticles->offsetSet( $oOrderArticle->getId(), $oOrderArticle );
00652         }
00653     }
00654 
00666     protected function _executePayment( oxBasket $oBasket, $oUserpayment )
00667     {
00668         $oPayTransaction = $this->_getGateway();
00669         $oPayTransaction->setPaymentParams( $oUserpayment );
00670 
00671         if ( !$oPayTransaction->executePayment( $oBasket->getPrice()->getBruttoPrice(), $this ) ) {
00672             $this->delete();
00673 
00674             // checking for error messages
00675             if ( method_exists( $oPayTransaction, 'getLastError' ) ) {
00676                 if ( ( $sLastError = $oPayTransaction->getLastError() ) ) {
00677                     return $sLastError;
00678                 }
00679             }
00680 
00681             // checking for error codes
00682             if ( method_exists( $oPayTransaction, 'getLastErrorNo' ) ) {
00683                 if ( ( $iLastErrorNo = $oPayTransaction->getLastErrorNo() ) ) {
00684                     return $iLastErrorNo;
00685                 }
00686             }
00687 
00688             return 2; // means no authentication
00689         }
00690         return true; // everything fine
00691     }
00692 
00699     protected function _getGateway()
00700     {
00701         return oxNew( 'oxPaymentGateway' );
00702     }
00703 
00711     protected function _setPayment( $sPaymentid )
00712     {
00713         // copying payment info fields
00714         $aDynvalue = oxSession::getVar( 'dynvalue' );
00715         $aDynvalue = $aDynvalue ? $aDynvalue : oxConfig::getParameter( 'dynvalue' );
00716 
00717         // loading payment object
00718         $oPayment = oxNew( 'oxpayment' );
00719 
00720         if (!$oPayment->load( $sPaymentid )) {
00721             return null;
00722         }
00723 
00724         // #756M Preserve already stored payment information
00725         if ( !$aDynvalue && ( $oUserpayment = $this->getPaymentType() ) ) {
00726             $aStoredDynvalue = $oUserpayment->getDynValues();
00727             foreach ( $aStoredDynvalue as $oVal ) {
00728                 $aDynvalue[$oVal->name] = $oVal->value;
00729             }
00730         }
00731 
00732         $oPayment->setDynValues( oxUtils::getInstance()->assignValuesFromText( $oPayment->oxpayments__oxvaldesc->value ) );
00733 
00734         // collecting dynamic values
00735         $aDynVal = array();
00736 
00737         $aPaymentDynValues = $oPayment->getDynValues();
00738         foreach ( $aPaymentDynValues  as $key => $oVal ) {
00739             if ( isset( $aDynvalue[$oVal->name] ) ) {
00740                 $oVal->value = $aDynvalue[$oVal->name];
00741             }
00742 
00743             //$oPayment->setDynValue($key, $oVal);
00744             $aPaymentDynValues[$key] = $oVal;
00745             $aDynVal[$oVal->name] = $oVal->value;
00746         }
00747 
00748         // Store this payment information, we might allow users later to
00749         // reactivate already give payment informations
00750 
00751         $oUserpayment = oxNew( 'oxuserpayment' );
00752         $oUserpayment->oxuserpayments__oxuserid     = clone $this->oxorder__oxuserid;
00753         $oUserpayment->oxuserpayments__oxpaymentsid = new oxField($sPaymentid, oxField::T_RAW);
00754         $oUserpayment->oxuserpayments__oxvalue      = new oxField(oxUtils::getInstance()->assignValuesToText( $aDynVal ), oxField::T_RAW);
00755         $oUserpayment->oxpayments__oxdesc           = clone $oPayment->oxpayments__oxdesc;
00756         $oUserpayment->setDynValues( $aPaymentDynValues );
00757         $oUserpayment->save();
00758 
00759         // storing payment information to order
00760         $this->oxorder__oxpaymentid   = new oxField($oUserpayment->getId(), oxField::T_RAW);
00761         $this->oxorder__oxpaymenttype = clone $oUserpayment->oxuserpayments__oxpaymentsid;
00762 
00763         // returning user payment object which will be used later in code ...
00764         return $oUserpayment;
00765     }
00766 
00772     protected function _setFolder()
00773     {
00774         $myConfig = $this->getConfig();
00775         $this->oxorder__oxfolder    = new oxField(key( $myConfig->getShopConfVar(  'aOrderfolder', $myConfig->getShopId() ) ), oxField::T_RAW);
00776     }
00777 
00787     protected function _updateWishlist( $aArticleList, $oUser )
00788     {
00789 
00790         foreach ( $aArticleList as $oContent) {
00791             if ( ( $sWishId = $oContent->getWishId() ) ) {
00792 
00793                 // checking which wishlist user uses ..
00794                 if ( $sWishId == $oUser->getId() ) {
00795                     $oUserBasket = $oUser->getBasket( 'wishlist' );
00796                 } else {
00797                     $aWhere = array( 'oxuserbaskets.oxuserid' => $sWishId, 'oxuserbaskets.oxtitle' => 'wishlist' );
00798                     $oUserBasket = oxNew( 'oxuserbasket' );
00799                     $oUserBasket->assignRecord( $oUserBasket->buildSelectString( $aWhere ) );
00800                 }
00801 
00802                 // updating users wish list
00803                 if ( $oUserBasket ) {
00804                     if ( !($sProdId = $oContent->getWishArticleId() )) {
00805                         $sProdId = $oContent->getProductId();
00806                     }
00807                     $oUserBasketItem = $oUserBasket->getItem( $sProdId, $oContent->getSelList() );
00808                     $dNewAmount = $oUserBasketItem->oxuserbasketitems__oxamount->value - $oContent->getAmount();
00809                     if ( $dNewAmount < 0) {
00810                         $dNewAmount = 0;
00811                     }
00812                     $oUserBasket->addItemToBasket( $sProdId, $dNewAmount, $oContent->getSelList(), true );
00813                 }
00814             }
00815         }
00816     }
00817 
00827     protected function _updateNoticeList( $aArticleList, $oUser )
00828     {
00829         // loading users notice list ..
00830         if ( $oUserBasket = $oUser->getBasket( 'noticelist' ) ) {
00831             // only if wishlist is enabled
00832             foreach ( $aArticleList as $oContent) {
00833                 $sProdId = $oContent->getProductId();
00834 
00835                 // updating users notice list
00836                 $oUserBasketItem = $oUserBasket->getItem( $sProdId, $oContent->getSelList() );
00837                 $dNewAmount = $oUserBasketItem->oxuserbasketitems__oxamount->value - $oContent->getAmount();
00838                 if ( $dNewAmount < 0) {
00839                     $dNewAmount = 0;
00840                 }
00841                 $oUserBasket->addItemToBasket( $sProdId, $dNewAmount, $oContent->getSelList(), true );
00842             }
00843         }
00844     }
00845 
00851     protected function _updateStock()
00852     {
00853         $myConfig = $this->getConfig();
00854         $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00855 
00856         // ordered articles
00857         $oOrderArticles = $this->getOrderArticles();
00858         if ( $oOrderArticles && count( $oOrderArticles ) > 0 && $blUseStock ) {
00859             foreach ( $oOrderArticles as $oOrderArticle ) {
00860                 $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value * (-1), $myConfig->getConfigParam( 'blAllowNegativeStock' ) );
00861             }
00862         }
00863     }
00864 
00876     protected function _markVouchers( $oBasket, $oUser )
00877     {
00878         $this->_aVoucherList = $oBasket->getVouchers();
00879 
00880         if ( is_array( $this->_aVoucherList ) ) {
00881             foreach ( array_keys( $this->_aVoucherList ) as $sVoucherId ) {
00882                 $oVoucher = oxNew( 'oxvoucher' );
00883                 $oVoucher->load( $sVoucherId );
00884                 $oVoucher->markAsUsed( $this->oxorder__oxid->value, $oUser->oxuser__oxid->value );
00885 
00886                 // -- set deprecated values for email templates
00887                 $oVoucher->oxmodvouchers__oxvouchernr = $oVoucher->oxvouchers__oxvouchernr;
00888                 $oVSerie = $oVoucher->getSerie();
00889                 $oVoucher->oxmodvouchers__oxdiscount     = clone $oVSerie->oxvoucherseries__oxdiscount;
00890                 $oVoucher->oxmodvouchers__oxdiscounttype = clone $oVSerie->oxvoucherseries__oxdiscounttype;
00891                 // -- set deprecated values for email templates
00892 
00893                 $this->_aVoucherList[$sVoucherId] = $oVoucher;
00894             }
00895         }
00896     }
00897 
00903     public function save()
00904     {
00905         if ( ( $blSave = parent::save() ) ) {
00906 
00907             // saving order articles
00908             $oOrderArticles = $this->getOrderArticles();
00909             if ( $oOrderArticles && count( $oOrderArticles ) > 0 ) {
00910                 foreach ( $oOrderArticles as $oOrderArticle ) {
00911                     $oOrderArticle->save();
00912                 }
00913             }
00914         }
00915 
00916         return $blSave;
00917     }
00918 
00925     public function getDelAddressInfo()
00926     {
00927         $oDelAdress = null;
00928         if ( ( $soxAddressId = oxConfig::getParameter( 'deladrid' ) ) ) {
00929             $oDelAdress = oxNew( 'oxbase' );
00930             $oDelAdress->init( 'oxaddress' );
00931             $oDelAdress->load( $soxAddressId );
00932 
00933             //get delivery country name from delivery country id
00934             if ( $oDelAdress->oxaddress__oxcountryid->value && $oDelAdress->oxaddress__oxcountryid->value != -1 ) {
00935                  $oCountry = oxNew( 'oxcountry' );
00936                  $oCountry->load( $oDelAdress->oxaddress__oxcountryid->value );
00937                  $oDelAdress->oxaddress__oxcountry = clone $oCountry->oxcountry__oxtitle;
00938             }
00939         }
00940         return $oDelAdress;
00941     }
00942 
00953     public function validateStock( $oBasket )
00954     {
00955         foreach ( $oBasket->getContents() as $oContent ) {
00956             $oProd = $oContent->getArticle();
00957 
00958             // check if its still available
00959             $iOnStock = $oProd->checkForStock( $oContent->getAmount() );
00960             if ( $iOnStock !== true ) {
00961                 $oEx = oxNew( 'oxOutOfStockException' );
00962                 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
00963                 $oEx->setArticleNr( $oProd->oxarticles__oxartnum->value );
00964                 $oEx->setRemainingAmount( $oProd->oxarticles__oxstock->value );
00965                 throw $oEx;
00966             }
00967         }
00968     }
00969 
00975     protected function _insert()
00976     {
00977         $myConfig = $this->getConfig();
00978         $oUtilsDate = oxUtilsDate::getInstance();
00979 
00980         //V #M525 orderdate must be the same as it was
00981         if ( !$this->oxorder__oxorderdate->value ) {
00982             $this->oxorder__oxorderdate = new oxField(date( 'Y-m-d H:i:s', $oUtilsDate->getTime() ), oxField::T_RAW);
00983         } else {
00984             $this->oxorder__oxorderdate = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxorderdate->value, true ));
00985         }
00986         $this->oxorder__oxshopid    = new oxField($myConfig->getShopId(), oxField::T_RAW);
00987 
00988         $this->oxorder__oxsenddate  = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxsenddate->value, true ));
00989 
00990         if ( ( $blInsert = parent::_insert() ) ) {
00991             // setting order number
00992             if ( !$this->oxorder__oxordernr->value ) {
00993                 $aWhere = '';
00994                 // separate order numbers for shops ...
00995                 if ( $this->_blSeparateNumbering ) {
00996                     $aWhere = array( 'oxshopid = "'.$myConfig->getShopId().'"' );
00997                 }
00998                 $this->_setRecordNumber( 'oxordernr', $aWhere );
00999             }
01000         }
01001         return $blInsert;
01002     }
01003 
01009     protected function _update()
01010     {
01011         $this->oxorder__oxsenddate = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxorder__oxsenddate->value, true ));
01012         return parent::_update();
01013     }
01014 
01023     public function delete( $sOxId = null )
01024     {
01025         if ( $sOxId ) {
01026             if ( !$this->load( $sOxId ) ) {
01027                 // such order does not exist
01028                 return false;
01029             }
01030         } elseif ( !$sOxId ) {
01031             $sOxId = $this->getId();
01032         }
01033 
01034         // no order id is passed
01035         if ( !$sOxId ) {
01036             return false;
01037         }
01038 
01039 
01040         // update article stock information and delete order articles
01041         $myConfig   = $this->getConfig();
01042         $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
01043 
01044         $oOrderArticles = $this->getOrderArticles();
01045         foreach ( $oOrderArticles as $oOrderArticle ) {
01046             // updating amounts only on non canceled items
01047             if ( $blUseStock ) {
01048                 if ( !$oOrderArticle->oxorderarticles__oxstorno->value ) {
01049                     $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value, $myConfig->getConfigParam('blAllowNegativeStock') );
01050                 }
01051             }
01052             $oOrderArticle->delete();
01053         }
01054 
01055         // #440 - deleting user payment info
01056         if ( $oPaymentType = $this->getPaymentType() ) {
01057             $oPaymentType->delete();
01058         }
01059 
01060         return parent::delete( $sOxId );
01061     }
01062 
01074     public function recalculateOrder( $aNewOrderArticles = array(), $blChangeDelivery = false, $blChangeDiscount = false )
01075     {
01076         oxDb::startTransaction();
01077 
01078         try {
01079             // deleting old order with order articles
01080             //load order articles and delete order and order articles
01081             $this->delete();
01082 
01083             $oUser = oxNew( "oxuser" );
01084             $oUser->load( $this->oxorder__oxuserid->value );
01085 
01086             //creating virtual basket and initalizing additional parameters (user, stock, currency)
01087             $oBasket = oxNew( "oxBasket" );
01088 
01089             $aCanceledArticles = array();
01090             $aArticlesIds = array();
01091 
01092             // collect order articles ids's (oxarticles) and canceled order articles
01093             if ( $this->_oArticles = $this->getOrderArticles() ) {
01094                 $this->_oArticles->rewind();
01095                 while ( $oOrderArticle = $this->_oArticles->current() ) {
01096                     $sOrderArticleId = $this->_oArticles->key();
01097 
01098                     //articles id's
01099                     $aArticlesIds[$sOrderArticleId] = $oOrderArticle->oxorderarticles__oxartid->value;
01100 
01101                     // collect canceled order articles, they will not be included in recalculation articles list
01102                     // and will be saved back to order after recalculating and finalizieOrder()
01103                     if ( $oOrderArticle->oxorderarticles__oxstorno->value == '1') {
01104                         $aCanceledArticles[$sOrderArticleId] = $oOrderArticle;
01105 
01106                         // unset canceled article from recalcualtion list
01107                         //unset( $this->_oArticles[$sOrderArticleId] );
01108                         $this->_oArticles->offsetUnset( $sOrderArticleId );
01109                     } else {
01110                           $this->_oArticles->next();
01111                     }
01112                 }
01113             }
01114 
01115             // add or remove newly added order articles to/from old articles list
01116             foreach ($aNewOrderArticles as $oNewOrderArticle) {
01117 
01118                 $sNewOrderArtId = null;
01119                 $blIsOldOrderArticle = false;
01120 
01121                 //check, if added article already is in old order articles list
01122                 if ( ( $sNewOrderArtId = array_search( $oNewOrderArticle->oxorderarticles__oxartid->value, $aArticlesIds ) ) !== false ) {
01123                     $blIsOldOrderArticle = true;
01124                 }
01125 
01126                 //check, if we are going to delete it
01127                 if ( $oNewOrderArticle->oxorderarticles__oxamount->value == 0 ) {
01128                     // if it is in canceled articles list, remove it from canceled articles list,
01129                     // because they will be restored after recalcualtion
01130                     if ( array_key_exists( $sNewOrderArtId, $aCanceledArticles) ) {
01131                         // add it back to recalculation list from canceled articles list
01132                         // to delete it in finalizeOrder()
01133                         $this->_oArticles->offsetSet( $sNewOrderArtId, $aCanceledArticles[$sNewOrderArtId] );
01134                         //$this->_oArticles[$sNewOrderArtId] = $aCanceledArticles[$sNewOrderArtId];
01135 
01136                         // and remove it from canceled articles, because they will be restored after recalculation
01137                         unset($aCanceledArticles[$sNewOrderArtId]);
01138                     }
01139                 }
01140 
01141                 if ( $blIsOldOrderArticle ) {
01142                     //just update existing order article amount
01143                     $this->_oArticles->offsetGet( $sNewOrderArtId )->oxorderarticles__oxamount = clone $oNewOrderArticle->oxorderarticles__oxamount;
01144                     //$this->_oArticles[$sNewOrderArtId]->oxorderarticles__oxamount = clone $oNewOrderArticle->oxorderarticles__oxamount;
01145                 } else {
01146                     //add new article to order articles
01147                     $this->_oArticles->offsetSet( $oNewOrderArticle->getId(), $oNewOrderArticle );
01148                     //$this->_oArticles[] = $oNewOrderArticle;
01149                 }
01150             }
01151 
01152             // add this order articles to virtual basket and recalculates basket
01153             $oBasket = $this->_addOrderArticlesToBasket( $oUser, $this->_oArticles, $blChangeDelivery, $blChangeDiscount );
01154 
01155             //finalizing order (skipping payment execution, vouchers marking and mail sending)
01156             $iRet = $this->finalizeOrder( $oBasket, $oUser, true );
01157 
01158             //adding back canceled articles
01159             if ( count($aCanceledArticles) > 0 ) {
01160                 foreach ($aCanceledArticles as $oCanceledOrderArticle ) {
01161                     $oCanceledOrderArticle->save();
01162                 }
01163             }
01164 
01165             //if finalizing order failed, rollback transaction
01166             if ( $iRet !== 1 ) {
01167                 oxDb::rollbackTransaction();
01168             } else {
01169                 oxDb::commitTransaction();
01170             }
01171 
01172         } catch( Exception $oE ) {
01173                 // if exception, rollBack everything
01174                 oxDb::rollbackTransaction();
01175         }
01176     }
01177 
01185     public function pdfFooter( $oPdf )
01186     {
01187     }
01188 
01196     public function pdfHeaderplus( $oPdf )
01197     {
01198     }
01199 
01207     public function pdfHeader( $oPdf )
01208     {
01209     }
01210 
01219     public function genPdf( $sFilename, $iSelLang = 0 )
01220     {
01221     }
01222 
01228     public function getInvoiceNum()
01229     {
01230         $sQ = 'select max(oxorder.oxinvoicenr) from oxorder where oxorder.oxshopid = "'.$this->getConfig()->getShopId().'" ';
01231         return ( ( int ) oxDb::getDb()->getOne( $sQ ) + 1 );
01232     }
01233 
01239     public function getNextBillNum()
01240     {
01241         $sQ = 'select max(oxorder.oxbillnr) from oxorder where oxorder.oxshopid = "'.$this->getConfig()->getShopId().'" ';
01242         return ( ( int ) oxDb::getDb()->getOne( $sQ ) + 1 );
01243     }
01244 
01250     public function getShippingSetList()
01251     {
01252         // in which country we deliver
01253         if ( !( $sShipId = $this->oxorder__oxdelcountryid->value ) ) {
01254             $sShipId = $this->oxorder__oxbillcountryid->value;
01255         }
01256 
01257         $oUser = oxNew( "oxuser" );
01258         $oUser->load( $this->oxorder__oxuserid->value );
01259 
01260         // add this order articles to basket and recalculate basket
01261         $oBasket = $this->_addOrderArticlesToBasket( $oUser, $this->getOrderArticles(), false, false, false );
01262 
01263         // load fitting deliveries list
01264         $oDeliveryList = oxNew( "oxDeliveryList", "core" );
01265         $oDeliveryList->setCollectFittingDeliveriesSets( true );
01266 
01267         return $oDeliveryList->getDeliveryList( $oBasket, $oUser, $sShipId );
01268     }
01269 
01275     public function getVoucherNrList()
01276     {
01277         $oDB = oxDb::getDb( true );
01278         $aVouchers = array();
01279         $sSelect = "select oxvouchernr from oxvouchers where oxorderid = '".$this->oxorder__oxid->value."'";
01280         $rs = $oDB->execute( $sSelect);
01281         if ($rs != false && $rs->recordCount() > 0) {
01282             while (!$rs->EOF) {
01283                 $aVouchers[] = $rs->fields['oxvouchernr'];
01284                 $rs->moveNext();
01285             }
01286         }
01287         return $aVouchers;
01288     }
01289 
01297     public function getOrderSum( $blToday = false )
01298     {
01299         $sSelect  = 'select sum(oxtotalordersum / oxcurrate) from oxorder where ';
01300         $sSelect .= 'oxshopid = "'.$this->getConfig()->getShopId().'" and oxorder.oxstorno != "1" ';
01301 
01302         if ( $blToday ) {
01303             $sSelect .= 'and oxorderdate like "'.date( 'Y-m-d').'%" ';
01304         }
01305 
01306         return ( double ) oxDb::getDb()->getOne( $sSelect );
01307     }
01308 
01316     public function getOrderCnt( $blToday = false )
01317     {
01318         $sSelect  = 'select count(*) from oxorder where ';
01319         $sSelect .= 'oxshopid = "'.$this->getConfig()->getShopId().'"  and oxorder.oxstorno != "1" ';
01320 
01321         if ( $blToday ) {
01322             $sSelect .= 'and oxorderdate like "'.date( 'Y-m-d').'%" ';
01323         }
01324 
01325         return ( int ) oxDb::getDb()->getOne( $sSelect );
01326     }
01327 
01328 
01336     protected function _checkOrderExist( $sOxId = null )
01337     {
01338         if ( !$sOxId) {
01339             return false;
01340         }
01341 
01342         if ( oxDb::getDb()->getOne( 'select oxid from oxorder where oxid = "'.$sOxId.'"' ) ) {
01343             return true;
01344         }
01345 
01346         return false;
01347     }
01348 
01358     protected function _sendOrderByEmail( $oUser = null, $oBasket = null, $oPayment = null )
01359     {
01360         $iRet = 0;
01361 
01362         // add user, basket and payment to order
01363         $this->_oUser    = $oUser;
01364         $this->_oBasket  = $oBasket;
01365         $this->_oPayment = $oPayment;
01366 
01367         $oxEmail = oxNew( 'oxemail' );
01368 
01369         // send order email to user
01370         if ( $oxEmail->sendOrderEMailToUser( $this ) ) {
01371             // mail to user was successfully sent
01372             $iRet = 1;
01373         }
01374 
01375         // send order email to shop owner
01376         $oxEmail->sendOrderEMailToOwner( $this );
01377 
01378         return $iRet;
01379     }
01380 
01386     public function getUser()
01387     {
01388         return $this->_oUser;
01389     }
01390 
01396     public function getBasket()
01397     {
01398         return $this->_oBasket;
01399     }
01400 
01406     public function getPayment()
01407     {
01408         return $this->_oPayment;
01409     }
01410 
01416     public function getVoucherList()
01417     {
01418         return $this->_aVoucherList;
01419     }
01420 
01426     public function getDelSet()
01427     {
01428         if ( $this->_oDelSet == null ) {
01429             // load deliveryset info
01430             $this->_oDelSet = oxNew( 'oxdeliveryset' );
01431             $this->_oDelSet->load( $this->oxorder__oxdeltype->value );
01432         }
01433 
01434         return $this->_oDelSet;
01435     }
01436 
01442     public function getPaymentType()
01443     {
01444         if ( $this->oxorder__oxpaymentid->value && $this->_oPaymentType == null ) {
01445             $this->_oPaymentType = oxNew( 'oxuserpayment' );
01446             $this->_oPaymentType->load( $this->oxorder__oxpaymentid->value );
01447         }
01448 
01449         return $this->_oPaymentType;
01450     }
01451 
01457     public function getGiftCard()
01458     {
01459         if ( $this->oxorder__oxcardid->value && $this->_oGiftCard == null ) {
01460             $this->_oGiftCard = oxNew( 'oxwrapping' );
01461             $this->_oGiftCard->load( $this->oxorder__oxcardid->value );
01462         }
01463 
01464         return $this->_oGiftCard;
01465     }
01466 
01474     public function setSeparateNumbering( $blSeparateNumbering = null )
01475     {
01476         $this->_blSeparateNumbering = $blSeparateNumbering;
01477     }
01478 
01486     public function getLastUserPaymentType( $sUserId)
01487     {
01488         $sQ = 'select oxorder.oxpaymenttype from oxorder where oxorder.oxshopid="'.$this->getConfig()->getShopId().'" and oxorder.oxuserid="'.$sUserId.'" order by oxorder.oxorderdate desc ';
01489         $sLastPaymentId = oxDb::getDb()->getOne( $sQ );
01490         return $sLastPaymentId;
01491     }
01492 
01503     protected function _makeSelListArray( $sArtId = null, $sOrderArtSelList = null )
01504     {
01505         $aList = array();
01506         $aRet  = array();
01507 
01508         if ( $sArtId ) {
01509             $aList = explode( ",", $sOrderArtSelList );
01510             $oStr = getStr();
01511 
01512             //$oArticle = oxNew( "oxArticle", "core" );
01513             $oArticle = oxNew( "oxArticle" );
01514             $oArticle->load( $sArtId );
01515             $aArticleSelList = $oArticle->getSelectLists();
01516 
01517             //formating temporary list array from string
01518             foreach ( $aList as $sList ) {
01519                 if ( $sList ) {
01520 
01521                     $aVal = explode( ":", $sList );
01522                     if ( isset($aVal[0]) && isset($aVal[1])) {
01523                         $sOrderArtListTitle = $oStr->strtolower( trim($aVal[0]) );
01524                         $sOrderArtSelValue  = $oStr->strtolower( trim($aVal[1]) );
01525 
01526                         //checking article list for matches with article list stored in oxorderitem
01527                         $iSelListNum = 0;
01528                         if ( count($aArticleSelList) > 0 ) {
01529                             foreach ( $aArticleSelList as $aSelect ) {
01530                                 //chek if selects titles are equal
01531 
01532                                 if ( $oStr->strtolower($aSelect['name']) == $sOrderArtListTitle ) {
01533                                     //try to find matching select items value
01534                                     $iSelValueNum = 0;
01535                                     foreach ( $aSelect as $oSel ) {
01536                                         if ( $oStr->strtolower($oSel->name) == $sOrderArtSelValue ) {
01537                                             // found, adding tu return array
01538                                             $aRet[$iSelListNum] = $iSelValueNum;
01539                                         }
01540                                         //next article list item
01541                                         $iSelValueNum++;
01542                                     }
01543                                 }
01544                                 //next article list
01545                                 $iSelListNum++;
01546                             }
01547                         }
01548                     }
01549                 }
01550             }
01551         }
01552 
01553         return $aRet;
01554     }
01555 
01567     protected function _addOrderArticlesToBasket( $oUser = null, $aOrderArticles = null, $blChangeDelivery = false, $blChangeDiscount = false, $blStockCheck = true )
01568     {
01569         $oBasket = oxNew( "oxbasket" );
01570 
01571         // setting stock check mode
01572         $oBasket->setStockCheckMode( $blStockCheck );
01573 
01574         // setting virtual basket user
01575         $oBasket->setBasketUser( $oUser );
01576 
01577         // setting basket currency order uses
01578         $aCurrencies = $this->getConfig()->getCurrencyArray();
01579         foreach ( $aCurrencies as $oCur ) {
01580             if ($oCur->name == $this->oxorder__oxcurrency->value) {
01581                 $oBasketCur = $oCur;
01582                 break;
01583             }
01584         }
01585 
01586         $oBasket->setBasketCurrency( $oBasketCur );
01587 
01588         // if no order articles, return empty basket
01589         if ( count($aOrderArticles ) < 1 ) {
01590             return $oBasket;
01591         }
01592 
01593         //adding order articles to basket
01594         foreach ( $aOrderArticles as $oOrderArticle ) {
01595 
01596             $aPersParam = null;
01597             if ( $oOrderArticle->oxorderarticles__oxpersparam->value ) {
01598                 $aPersParam = unserialize( $oOrderArticle->oxorderarticles__oxpersparam->value );
01599             }
01600 
01601             $aSel = $this->_makeSelListArray( $oOrderArticle->oxorderarticles__oxartid->value,
01602                                               $oOrderArticle->oxorderarticles__oxselvariant->value );
01603 
01604             $oBasketItem = $oBasket->addToBasket( $oOrderArticle->oxorderarticles__oxartid->value,
01605                                                   $oOrderArticle->oxorderarticles__oxamount->value, $aSel, $aPersParam );
01606             if ( $oBasketItem ) {
01607                 $oBasketItem->setWrapping( $oOrderArticle->oxorderarticles__oxwrapid->value );
01608             }
01609         }
01610 
01611         // set basket card id and message
01612         $oBasket->setCardId( $this->oxorder__oxcardid->value );
01613         $oBasket->setCardMessage( $this->oxorder__oxcardtext->value );
01614 
01615         // set skip vouchers availability checking
01616         $oBasket->setSkipVouchersChecking( true );
01617 
01618         // add previously used vouchers
01619         $sQ = 'select oxid from oxvouchers where oxorderid = "'.$this->getId().'"';
01620         $aVouchers = oxDb::getDb( true )->getAll( $sQ );
01621         foreach ( $aVouchers AS $aVoucher ) {
01622             $oBasket->addVoucher($aVoucher['oxid']);
01623         }
01624 
01625         //set shipping
01626         $oBasket->setShipping( $this->oxorder__oxdeltype->value );
01627         //V #M429: Shipping and total prices were not calculated correct
01628         //when user changed delivery costs in admin
01629         if ( $blChangeDelivery ) {
01630             $oBasket->setDeliveryPrice( $this->getOrderDeliveryPrice() );
01631         }
01632         if ( $blChangeDiscount ) {
01633             $oBasket->setTotalDiscount( $this->oxorder__oxdiscount->value );
01634         }
01635         //set basket payment
01636         $oBasket->setPayment( $this->oxorder__oxpaymenttype->value );
01637 
01638         // recalculating basket
01639         $oBasket->calculateBasket( true );
01640 
01641         return $oBasket;
01642     }
01643 
01651     protected function _setDeprecatedValues()
01652     {
01653         if ( $this->oxorder__oxstorno->value != 1 ) {
01654             $oCur = $this->getConfig()->getActShopCurrencyObject();
01655             $oLang = oxLang::getInstance();
01656 
01657             $this->totalnetsum   = $this->oxorder__oxtotalnetsum->value;
01658             $this->totalbrutsum  = $this->oxorder__oxtotalbrutsum->value;
01659             $this->totalorder    = $this->oxorder__oxtotalordersum->value;
01660             $this->ftotalnetsum  = $oLang->formatCurrency( $this->oxorder__oxtotalnetsum->value, $oCur );
01661             $this->ftotalbrutsum = $oLang->formatCurrency( $this->oxorder__oxtotalbrutsum->value, $oCur );
01662             $this->fdelcost      = $oLang->formatCurrency( $this->oxorder__oxdelcost->value, $oCur );
01663             $this->fpaycost      = $oLang->formatCurrency( $this->oxorder__oxpaycost->value, $oCur );
01664             $this->fwrapcost     = $oLang->formatCurrency( $this->oxorder__oxwrapcost->value, $oCur );
01665             $this->ftotalorder   = $this->getTotalOrderSum();
01666             $this->totalvouchers = 0;
01667 
01668             if ( $this->oxorder__oxvoucherdiscount->value ) {
01669                 $this->totalvouchers  = $oLang->formatCurrency( $this->oxorder__oxvoucherdiscount->value, $oCur );
01670             }
01671 
01672             if ( $this->oxorder__oxdiscount->value ) {
01673                 $this->discount  = $this->oxorder__oxdiscount->value;
01674                 $this->fdiscount = $oLang->formatCurrency( $this->oxorder__oxdiscount->value, $oCur );
01675             }
01676         }
01677     }
01678 
01684     public function getTotalOrderSum()
01685     {
01686         $oCur = $this->getConfig()->getActShopCurrencyObject();
01687         return number_format( $this->oxorder__oxtotalordersum->value, $oCur->decimal, '.', '');
01688     }
01689 
01695     public function getBillCountry()
01696     {
01697         if( !$this->oxorder__oxbillcountry->value ) {
01698             $this->oxorder__oxbillcountry = new oxField($this->_getCountryTitle( $this->oxorder__oxbillcountryid->value ));
01699         }
01700         return $this->oxorder__oxbillcountry;
01701     }
01702 
01708     public function getDelCountry()
01709     {
01710         if( !$this->oxorder__oxdelcountry->value ) {
01711             $this->oxorder__oxdelcountry = new oxField($this->_getCountryTitle( $this->oxorder__oxdelcountryid->value ));
01712         }
01713         return $this->oxorder__oxdelcountry;
01714     }
01715 
01716 }

Generated on Wed May 13 13:25:51 2009 for OXID eShop CE by  doxygen 1.5.5