00001 <?php
00002
00007 class oxOrder extends oxBase
00008 {
00009
00014 const ORDER_STATE_MAILINGERROR = 0;
00015
00020 const ORDER_STATE_OK = 1;
00021
00026 const ORDER_STATE_PAYMENTERROR = 2;
00027
00032 const ORDER_STATE_ORDEREXISTS = 3;
00033
00038 const ORDER_STATE_INVALIDDELIVERY = 4;
00039
00044 const ORDER_STATE_INVALIDPAYMENT = 5;
00045
00051 protected $_aSkipSaveFields = array( 'oxorderdate' );
00052
00058 protected $_oArticles = null;
00059
00065 protected $_oDelSet = null;
00066
00072 protected $_oGiftCard = null;
00073
00079 protected $_oPaymentType = null;
00080
00086 protected $_oPayment = null;
00087
00093 protected $_aVoucherList = null;
00094
00100 protected $_oDelPrice = null;
00101
00107 protected $_oUser = null;
00108
00114 protected $_oBasket = null;
00115
00121 protected $_oWrappingPrice = null;
00122
00128 protected $_oPaymentPrice = null;
00129
00135 protected $_sClassName = 'oxorder';
00136
00142 protected $_blSeparateNumbering = null;
00143
00149 protected $_iOrderLang = null;
00150
00156 protected $_blReloadDelivery = true;
00157
00163 protected $_blReloadDiscount = true;
00164
00170 protected $_oOrderCurrency = null;
00171
00175 public function __construct()
00176 {
00177 parent::__construct();
00178 $this->init( 'oxorder' );
00179
00180
00181 $this->setSeparateNumbering( $this->getConfig()->getConfigParam( 'blSeparateNumbering') );
00182
00183 }
00184
00192 public function __get( $sName )
00193 {
00194 if ( $sName == 'oDelSet' ) {
00195 return $this->getDelSet();
00196 }
00197
00198 if ( $sName == 'oxorder__oxbillcountry' ) {
00199 return $this->getBillCountry();
00200 }
00201
00202 if ( $sName == 'oxorder__oxdelcountry' ) {
00203 return $this->getDelCountry();
00204 }
00205 }
00206
00214 public function assign( $dbRecord )
00215 {
00216
00217 parent::assign( $dbRecord );
00218
00219 $oUtilsDate = oxUtilsDate::getInstance();
00220
00221
00222 $this->oxorder__oxorderdate = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxorderdate->value));
00223 $this->oxorder__oxsenddate = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxsenddate->value));
00224
00225
00226 $this->_setDeprecatedValues();
00227 }
00228
00236 protected function _getCountryTitle( $sCountryId )
00237 {
00238 $sTitle = null;
00239 if ( $sCountryId && $sCountryId != '-1' ) {
00240 $oCountry = oxNew( 'oxcountry' );
00241 $oCountry->load( $sCountryId );
00242 $sTitle = $oCountry->oxcountry__oxtitle->value;
00243 }
00244
00245 return $sTitle;
00246 }
00247
00255 public function getOrderArticles( $blExcludeCanceled = false )
00256 {
00257
00258 if ( $this->_oArticles === null ) {
00259 $sTable = getViewName( "oxorderarticles" );
00260 $sSelect = "select {$sTable}.* from {$sTable}
00261 where {$sTable}.oxorderid = '".$this->getId() . "'" .
00262 ( $blExcludeCanceled ? " and {$sTable}.oxstorno != 1 ": " " ) ."
00263 order by {$sTable}.oxartid";
00264
00265
00266 $oArticles = oxNew( 'oxlist' );
00267 $oArticles->init( 'oxorderarticle' );
00268 $oArticles->selectString( $sSelect );
00269
00270
00271 return $oArticles;
00272 }
00273 return $this->_oArticles;
00274 }
00275
00283 public function setOrderArticleList( $aOrderArticleList )
00284 {
00285 $this->_oArticles = $aOrderArticleList;
00286 }
00287
00293 public function getOrderDeliveryPrice()
00294 {
00295 if ( $this->_oDelPrice != null ) {
00296 return $this->_oDelPrice;
00297 }
00298
00299 $this->_oDelPrice = oxNew( 'oxprice' );
00300 $this->_oDelPrice->setBruttoPriceMode();
00301 $this->_oDelPrice->setPrice( $this->oxorder__oxdelcost->value, $this->oxorder__oxdelvat->value );
00302 return $this->_oDelPrice;
00303 }
00304
00310 public function getOrderWrappingPrice()
00311 {
00312 if ( $this->_oWrappingPrice != null ) {
00313 return $this->_oWrappingPrice;
00314 }
00315
00316 $this->_oWrappingPrice = oxNew( 'oxprice' );
00317 $this->_oWrappingPrice->setBruttoPriceMode();
00318 $this->_oWrappingPrice->setPrice( $this->oxorder__oxwrapcost->value, $this->oxorder__oxwrapvat->value );
00319 return $this->_oWrappingPrice;
00320 }
00321
00327 public function getOrderPaymentPrice()
00328 {
00329 if ( $this->_oPaymentPrice != null ) {
00330 return $this->_oPaymentPrice;
00331 }
00332
00333 $this->_oPaymentPrice = oxNew( 'oxprice' );
00334 $this->_oPaymentPrice->setBruttoPriceMode();
00335 $this->_oPaymentPrice->setPrice( $this->oxorder__oxpaycost->value, $this->oxorder__oxpayvat->value );
00336 return $this->_oPaymentPrice;
00337 }
00338
00345 public function getOrderNetSum()
00346 {
00347 $dTotalNetSum = 0;
00348
00349 $dTotalNetSum += $this->oxorder__oxtotalnetsum->value;
00350 $dTotalNetSum += $this->getOrderDeliveryPrice()->getNettoPrice();
00351 $dTotalNetSum += $this->getOrderWrappingPrice()->getNettoPrice();
00352 $dTotalNetSum += $this->getOrderPaymentPrice()->getNettoPrice();
00353
00354 return $dTotalNetSum;
00355 }
00356
00377 public function finalizeOrder( oxBasket $oBasket, $oUser, $blRecalculatingOrder = false )
00378 {
00379
00380 $sGetChallenge = oxSession::getVar( 'sess_challenge' );
00381 if ( $this->_checkOrderExist( $sGetChallenge ) ) {
00382 oxUtils::getInstance()->logger( 'BLOCKER' );
00383
00384 return self::ORDER_STATE_ORDEREXISTS;
00385 }
00386
00387
00388 if ( !$blRecalculatingOrder ) {
00389
00390 $this->setId( $sGetChallenge );
00391
00392
00393 if ( $iOrderState = $this->validateOrder( $oBasket, $oUser ) ) {
00394 return $iOrderState;
00395 }
00396 }
00397
00398
00399 $this->_setUser( $oUser );
00400
00401
00402 $this->_loadFromBasket( $oBasket );
00403
00404
00405 $oUserPayment = $this->_setPayment( $oBasket->getPaymentId() );
00406
00407
00408
00409 if ( !$blRecalculatingOrder ) {
00410 $this->_setFolder();
00411 }
00412
00413
00414 $this->save();
00415
00416
00417
00418 if ( !$blRecalculatingOrder ) {
00419 $blRet = $this->_executePayment( $oBasket, $oUserPayment );
00420 if ( $blRet !== true ) {
00421 return $blRet;
00422 }
00423 }
00424
00425
00426 oxSession::deleteVar( 'ordrem' );
00427
00428
00429 $this->_setOrderStatus( 'OK' );
00430
00431
00432 $oBasket->setOrderId( $this->getId() );
00433
00434
00435 $this->_updateWishlist( $oBasket->getContents(), $oUser );
00436
00437
00438 $this->_updateNoticeList( $oBasket->getContents(), $oUser );
00439
00440
00441
00442 if ( !$blRecalculatingOrder ) {
00443 $this->_markVouchers( $oBasket, $oUser );
00444 }
00445
00446
00447
00448 if ( !$blRecalculatingOrder ) {
00449 $iRet = $this->_sendOrderByEmail( $oUser, $oBasket, $oUserPayment );
00450 } else {
00451 $iRet = self::ORDER_STATE_OK;
00452 }
00453
00454 return $iRet;
00455 }
00456
00464 protected function _setOrderStatus( $sStatus )
00465 {
00466 $oDb = oxDb::getDb();
00467 $sQ = 'update oxorder set oxtransstatus='.$oDb->quote( $sStatus ).' where oxid="'.$this->getId().'" ';
00468 $oDb->execute( $sQ );
00469
00470
00471 $this->oxorder__oxtransstatus = new oxField( $sStatus, oxField::T_RAW );
00472 }
00473
00484 protected function _loadFromBasket( oxBasket $oBasket )
00485 {
00486 $myConfig = $this->getConfig();
00487
00488
00489 if ( $myConfig->getConfigParam( 'blStoreIPs' ) && $this->oxorder__oxip->value === null ) {
00490 $this->oxorder__oxip = new oxField(oxUtilsServer::getInstance()->getRemoteAddress(), oxField::T_RAW);
00491 }
00492
00493
00494 $this->oxorder__oxtotalnetsum = new oxField(oxUtils::getInstance()->fRound($oBasket->getDiscountedNettoPrice()), oxField::T_RAW);
00495 $this->oxorder__oxtotalbrutsum = new oxField($oBasket->getProductsPrice()->getBruttoSum(), oxField::T_RAW);
00496 $this->oxorder__oxtotalordersum = new oxField($oBasket->getPrice()->getBruttoPrice(), oxField::T_RAW);
00497
00498
00499 $iVatIndex = 1;
00500 foreach ( $oBasket->getProductVats(false) as $iVat => $dPrice ) {
00501 $this->{"oxorder__oxartvat$iVatIndex"} = new oxField($iVat, oxField::T_RAW);
00502 $this->{"oxorder__oxartvatprice$iVatIndex"} = new oxField($dPrice, oxField::T_RAW);
00503 $iVatIndex ++;
00504 }
00505
00506
00507 if ( ( $oPaymentCost = $oBasket->getCosts( 'oxpayment' ) ) ) {
00508 $this->oxorder__oxpaycost = new oxField($oPaymentCost->getBruttoPrice(), oxField::T_RAW);
00509 $this->oxorder__oxpayvat = new oxField($oPaymentCost->getVAT(), oxField::T_RAW);
00510 }
00511
00512
00513 if ( ( $oDeliveryCost = $oBasket->getCosts( 'oxdelivery' ) ) ) {
00514 $this->oxorder__oxdelcost = new oxField($oDeliveryCost->getBruttoPrice(), oxField::T_RAW);
00515
00516 $this->oxorder__oxdelvat = new oxField($oDeliveryCost->getVAT(), oxField::T_RAW);
00517 $this->oxorder__oxdeltype = new oxField($oBasket->getShippingId(), oxField::T_RAW);
00518 }
00519
00520
00521 if ( $this->oxorder__oxremark->value === null ) {
00522 $this->oxorder__oxremark = new oxField(oxSession::getVar( 'ordrem' ), oxField::T_RAW);
00523 }
00524
00525
00526 $oCur = $myConfig->getActShopCurrencyObject();
00527 $this->oxorder__oxcurrency = new oxField($oCur->name);
00528 $this->oxorder__oxcurrate = new oxField($oCur->rate, oxField::T_RAW);
00529
00530
00531 if ( ( $oVoucherDiscount = $oBasket->getVoucherDiscount() ) ) {
00532 $this->oxorder__oxvoucherdiscount = new oxField($oVoucherDiscount->getBruttoPrice(), oxField::T_RAW);
00533 }
00534
00535
00536 if ( $this->_blReloadDiscount ) {
00537 $dDiscount = 0;
00538 $aDiscounts = $oBasket->getDiscounts();
00539 if ( count($aDiscounts) > 0 ) {
00540 foreach ($aDiscounts as $oDiscount) {
00541 $dDiscount += $oDiscount->dDiscount;
00542 }
00543 }
00544 $this->oxorder__oxdiscount = new oxField($dDiscount, oxField::T_RAW);
00545 }
00546
00547
00548 $this->oxorder__oxlang = new oxField( $this->getOrderLanguage() );
00549
00550
00551
00552 $this->oxorder__oxtransstatus = new oxField('ERROR', oxField::T_RAW);
00553
00554
00555 $this->_setOrderArticles( $oBasket->getContents() );
00556
00557
00558 $this->_setWrapping( $oBasket );
00559 }
00560
00567 public function getOrderLanguage()
00568 {
00569 if ( $this->_iOrderLang === null ) {
00570 if ( isset( $this->oxorder__oxlang->value ) ) {
00571 $this->_iOrderLang = oxLang::getInstance()->validateLanguage( $this->oxorder__oxlang->value );
00572 } else {
00573 $this->_iOrderLang = oxLang::getInstance()->getBaseLanguage();
00574 }
00575 }
00576 return $this->_iOrderLang;
00577 }
00578
00586 protected function _setUser( $oUser )
00587 {
00588
00589 $this->oxorder__oxuserid = new oxField($oUser->getId());
00590
00591
00592 $this->oxorder__oxbillcompany = clone $oUser->oxuser__oxcompany;
00593 $this->oxorder__oxbillemail = clone $oUser->oxuser__oxusername;
00594 $this->oxorder__oxbillfname = clone $oUser->oxuser__oxfname;
00595 $this->oxorder__oxbilllname = clone $oUser->oxuser__oxlname;
00596 $this->oxorder__oxbillstreet = clone $oUser->oxuser__oxstreet;
00597 $this->oxorder__oxbillstreetnr = clone $oUser->oxuser__oxstreetnr;
00598 $this->oxorder__oxbilladdinfo = clone $oUser->oxuser__oxaddinfo;
00599 $this->oxorder__oxbillustid = clone $oUser->oxuser__oxustid;
00600 $this->oxorder__oxbillcity = clone $oUser->oxuser__oxcity;
00601 $this->oxorder__oxbillcountryid = clone $oUser->oxuser__oxcountryid;
00602 $this->oxorder__oxbillstateid = clone $oUser->oxuser__oxstateid;
00603 $this->oxorder__oxbillzip = clone $oUser->oxuser__oxzip;
00604 $this->oxorder__oxbillfon = clone $oUser->oxuser__oxfon;
00605 $this->oxorder__oxbillfax = clone $oUser->oxuser__oxfax;
00606 $this->oxorder__oxbillsal = clone $oUser->oxuser__oxsal;
00607
00608
00609
00610 if ( ( $oDelAdress = $this->getDelAddressInfo() ) ) {
00611
00612 $this->oxorder__oxdelcompany = clone $oDelAdress->oxaddress__oxcompany;
00613 $this->oxorder__oxdelfname = clone $oDelAdress->oxaddress__oxfname;
00614 $this->oxorder__oxdellname = clone $oDelAdress->oxaddress__oxlname;
00615 $this->oxorder__oxdelstreet = clone $oDelAdress->oxaddress__oxstreet;
00616 $this->oxorder__oxdelstreetnr = clone $oDelAdress->oxaddress__oxstreetnr;
00617 $this->oxorder__oxdeladdinfo = clone $oDelAdress->oxaddress__oxaddinfo;
00618 $this->oxorder__oxdelcity = clone $oDelAdress->oxaddress__oxcity;
00619 $this->oxorder__oxdelcountryid = clone $oDelAdress->oxaddress__oxcountryid;
00620 $this->oxorder__oxdelstateid = clone $oDelAdress->oxaddress__oxstateid;
00621 $this->oxorder__oxdelzip = clone $oDelAdress->oxaddress__oxzip;
00622 $this->oxorder__oxdelfon = clone $oDelAdress->oxaddress__oxfon;
00623 $this->oxorder__oxdelfax = clone $oDelAdress->oxaddress__oxfax;
00624 $this->oxorder__oxdelsal = clone $oDelAdress->oxaddress__oxsal;
00625 }
00626 }
00627
00635 protected function _setWrapping( oxBasket $oBasket )
00636 {
00637 $myConfig = $this->getConfig();
00638
00639
00640 if ( ( $oWrappingCost = $oBasket->getCosts( 'oxwrapping' ) ) ) {
00641 $this->oxorder__oxwrapcost = new oxField($oWrappingCost->getBruttoPrice(), oxField::T_RAW);
00642
00643
00644 if ( $myConfig->getConfigParam( 'blCalcVatForWrapping' ) ) {
00645 $this->oxorder__oxwrapvat = new oxField($oWrappingCost->getVAT(), oxField::T_RAW);
00646 }
00647 }
00648
00649
00650 $this->oxorder__oxcardid = new oxField($oBasket->getCardId(), oxField::T_RAW);
00651
00652
00653 $this->oxorder__oxcardtext = new oxField($oBasket->getCardMessage(), oxField::T_RAW);
00654 }
00655
00664 protected function _setOrderArticles( $aArticleList )
00665 {
00666
00667 $this->_oArticles = oxNew( 'oxlist' );
00668 $iCurrLang = $this->getOrderLanguage();
00669
00670
00671 foreach ( $aArticleList as $oContent ) {
00672
00673
00674
00675 $oProduct = $oContent->getArticle( true, null, true);
00676
00677
00678 if ( $oProduct->isOrderArticle() ) {
00679 $oOrderArticle = $oProduct;
00680 } else {
00681
00682
00683 if ( $iCurrLang != $oProduct->getLanguage() ) {
00684 $oProduct->loadInLang( $iCurrLang, $oProduct->getProductId() );
00685 }
00686
00687
00688 $sSelList = '';
00689 if ( count( $aChosenSelList = $oContent->getChosenSelList() ) ) {
00690 foreach ( $aChosenSelList as $oItem ) {
00691 if ( $sSelList ) {
00692 $sSelList .= ", ";
00693 }
00694 $sSelList .= "{$oItem->name} : {$oItem->value}";
00695 }
00696 }
00697
00698 $oOrderArticle = oxNew( 'oxorderarticle' );
00699 $oOrderArticle->setIsNewOrderItem( true );
00700 $oOrderArticle->copyThis( $oProduct );
00701 $oOrderArticle->setId();
00702
00703 $oOrderArticle->oxorderarticles__oxartnum = clone $oProduct->oxarticles__oxartnum;
00704 $oOrderArticle->oxorderarticles__oxselvariant = new oxField( trim( $sSelList.' '.$oProduct->oxarticles__oxvarselect->value ), oxField::T_RAW );
00705 $oOrderArticle->oxorderarticles__oxshortdesc = new oxField( $oProduct->oxarticles__oxshortdesc->value, oxField::T_RAW );
00706
00707 $oOrderArticle->oxorderarticles__oxtitle = new oxField( trim( $oProduct->oxarticles__oxtitle->value ), oxField::T_RAW );
00708
00709
00710 if ( !is_array( $aPersParams = $oProduct->getPersParams() ) ) {
00711 $aPersParams = $oContent->getPersParams();
00712 }
00713 if ( is_array( $aPersParams ) && count( $aPersParams )) {
00714 $oOrderArticle->oxorderarticles__oxpersparam = new oxField( serialize( $aPersParams ), oxField::T_RAW );
00715 }
00716 }
00717
00718
00719 $oOrderArticle->oxorderarticles__oxorderid = new oxField( $this->getId() );
00720 $oOrderArticle->oxorderarticles__oxartid = new oxField( $oContent->getProductId() );
00721 $oOrderArticle->oxorderarticles__oxamount = new oxField( $oContent->getAmount() );
00722
00723
00724 $oPrice = $oContent->getPrice();
00725 $oOrderArticle->oxorderarticles__oxnetprice = new oxField( $oPrice->getNettoPrice(), oxField::T_RAW );
00726 $oOrderArticle->oxorderarticles__oxvatprice = new oxField( $oPrice->getVatValue(), oxField::T_RAW );
00727 $oOrderArticle->oxorderarticles__oxbrutprice = new oxField( $oPrice->getBruttoPrice(), oxField::T_RAW );
00728 $oOrderArticle->oxorderarticles__oxvat = new oxField( $oPrice->getVat(), oxField::T_RAW );
00729
00730 $oUnitPtice = $oContent->getUnitPrice();
00731 $oOrderArticle->oxorderarticles__oxnprice = new oxField( $oUnitPtice->getNettoPrice(), oxField::T_RAW );
00732 $oOrderArticle->oxorderarticles__oxbprice = new oxField( $oUnitPtice->getBruttoPrice(), oxField::T_RAW );
00733
00734
00735 $oOrderArticle->oxorderarticles__oxwrapid = new oxField( $oContent->getWrappingId(), oxField::T_RAW );
00736
00737
00738 $oOrderArticle->oxorderarticles__oxordershopid = new oxField( $oContent->getShopId(), oxField::T_RAW );
00739
00740
00741
00742
00743 $oOrderArticle->oProduct = $oProduct;
00744
00745
00746 $this->_oArticles->offsetSet( $oOrderArticle->getId(), $oOrderArticle );
00747 }
00748 }
00749
00761 protected function _executePayment( oxBasket $oBasket, $oUserpayment )
00762 {
00763 $oPayTransaction = $this->_getGateway();
00764 $oPayTransaction->setPaymentParams( $oUserpayment );
00765
00766 if ( !$oPayTransaction->executePayment( $oBasket->getPrice()->getBruttoPrice(), $this ) ) {
00767 $this->delete();
00768
00769
00770 if ( method_exists( $oPayTransaction, 'getLastError' ) ) {
00771 if ( ( $sLastError = $oPayTransaction->getLastError() ) ) {
00772 return $sLastError;
00773 }
00774 }
00775
00776
00777 if ( method_exists( $oPayTransaction, 'getLastErrorNo' ) ) {
00778 if ( ( $iLastErrorNo = $oPayTransaction->getLastErrorNo() ) ) {
00779 return $iLastErrorNo;
00780 }
00781 }
00782
00783 return self::ORDER_STATE_PAYMENTERROR;
00784 }
00785 return true;
00786 }
00787
00794 protected function _getGateway()
00795 {
00796 return oxNew( 'oxPaymentGateway' );
00797 }
00798
00806 protected function _setPayment( $sPaymentid )
00807 {
00808
00809 $aDynvalue = oxSession::getVar( 'dynvalue' );
00810 $aDynvalue = $aDynvalue ? $aDynvalue : oxConfig::getParameter( 'dynvalue' );
00811
00812
00813 $oPayment = oxNew( 'oxpayment' );
00814
00815 if (!$oPayment->load( $sPaymentid )) {
00816 return null;
00817 }
00818
00819
00820 if ( !$aDynvalue && ( $oUserpayment = $this->getPaymentType() ) ) {
00821 if ( is_array( $aStoredDynvalue = $oUserpayment->getDynValues() ) ) {
00822 foreach ( $aStoredDynvalue as $oVal ) {
00823 $aDynvalue[$oVal->name] = $oVal->value;
00824 }
00825 }
00826 }
00827
00828 $oPayment->setDynValues( oxUtils::getInstance()->assignValuesFromText( $oPayment->oxpayments__oxvaldesc->value ) );
00829
00830
00831 $aDynVal = array();
00832
00833 if ( is_array( $aPaymentDynValues = $oPayment->getDynValues() ) ) {
00834 foreach ( $aPaymentDynValues as $key => $oVal ) {
00835 if ( isset( $aDynvalue[$oVal->name] ) ) {
00836 $oVal->value = $aDynvalue[$oVal->name];
00837 }
00838
00839
00840 $aPaymentDynValues[$key] = $oVal;
00841 $aDynVal[$oVal->name] = $oVal->value;
00842 }
00843 }
00844
00845
00846
00847
00848 $oUserpayment = oxNew( 'oxuserpayment' );
00849 $oUserpayment->oxuserpayments__oxuserid = clone $this->oxorder__oxuserid;
00850 $oUserpayment->oxuserpayments__oxpaymentsid = new oxField($sPaymentid, oxField::T_RAW);
00851 $oUserpayment->oxuserpayments__oxvalue = new oxField(oxUtils::getInstance()->assignValuesToText( $aDynVal ), oxField::T_RAW);
00852 $oUserpayment->oxpayments__oxdesc = clone $oPayment->oxpayments__oxdesc;
00853 $oUserpayment->oxpayments__oxlongdesc = clone $oPayment->oxpayments__oxlongdesc;
00854 $oUserpayment->setDynValues( $aPaymentDynValues );
00855 $oUserpayment->save();
00856
00857
00858 $this->oxorder__oxpaymentid = new oxField($oUserpayment->getId(), oxField::T_RAW);
00859 $this->oxorder__oxpaymenttype = clone $oUserpayment->oxuserpayments__oxpaymentsid;
00860
00861
00862 return $oUserpayment;
00863 }
00864
00870 protected function _setFolder()
00871 {
00872 $myConfig = $this->getConfig();
00873 $this->oxorder__oxfolder = new oxField(key( $myConfig->getShopConfVar( 'aOrderfolder', $myConfig->getShopId() ) ), oxField::T_RAW);
00874 }
00875
00885 protected function _updateWishlist( $aArticleList, $oUser )
00886 {
00887
00888 foreach ( $aArticleList as $oContent) {
00889 if ( ( $sWishId = $oContent->getWishId() ) ) {
00890
00891
00892 if ( $sWishId == $oUser->getId() ) {
00893 $oUserBasket = $oUser->getBasket( 'wishlist' );
00894 } else {
00895 $aWhere = array( 'oxuserbaskets.oxuserid' => $sWishId, 'oxuserbaskets.oxtitle' => 'wishlist' );
00896 $oUserBasket = oxNew( 'oxuserbasket' );
00897 $oUserBasket->assignRecord( $oUserBasket->buildSelectString( $aWhere ) );
00898 }
00899
00900
00901 if ( $oUserBasket ) {
00902 if ( !($sProdId = $oContent->getWishArticleId() )) {
00903 $sProdId = $oContent->getProductId();
00904 }
00905 $oUserBasketItem = $oUserBasket->getItem( $sProdId, $oContent->getSelList() );
00906 $dNewAmount = $oUserBasketItem->oxuserbasketitems__oxamount->value - $oContent->getAmount();
00907 if ( $dNewAmount < 0) {
00908 $dNewAmount = 0;
00909 }
00910 $oUserBasket->addItemToBasket( $sProdId, $dNewAmount, $oContent->getSelList(), true );
00911 }
00912 }
00913 }
00914 }
00915
00925 protected function _updateNoticeList( $aArticleList, $oUser )
00926 {
00927
00928 if ( $oUserBasket = $oUser->getBasket( 'noticelist' ) ) {
00929
00930 foreach ( $aArticleList as $oContent) {
00931 $sProdId = $oContent->getProductId();
00932
00933
00934 $oUserBasketItem = $oUserBasket->getItem( $sProdId, $oContent->getSelList() );
00935 $dNewAmount = $oUserBasketItem->oxuserbasketitems__oxamount->value - $oContent->getAmount();
00936 if ( $dNewAmount < 0) {
00937 $dNewAmount = 0;
00938 }
00939 $oUserBasket->addItemToBasket( $sProdId, $dNewAmount, $oContent->getSelList(), true );
00940 }
00941 }
00942 }
00943
00949 protected function _updateStock()
00950 {
00951 $myConfig = $this->getConfig();
00952
00953
00954 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00955 $oOrderArticles = $this->getOrderArticles();
00956 foreach ( $oOrderArticles as $oOrderArticle ) {
00957 if ( $oOrderArticle->isNewOrderItem() ) {
00958 $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value * (-1), $myConfig->getConfigParam( 'blAllowNegativeStock' ) );
00959 }
00960 }
00961 }
00962 }
00963
00975 protected function _markVouchers( $oBasket, $oUser )
00976 {
00977 $this->_aVoucherList = $oBasket->getVouchers();
00978
00979 if ( is_array( $this->_aVoucherList ) ) {
00980 foreach ( $this->_aVoucherList as $sVoucherId => $oSimpleVoucher) {
00981 $oVoucher = oxNew( 'oxvoucher' );
00982 $oVoucher->load( $sVoucherId );
00983 $oVoucher->markAsUsed( $this->oxorder__oxid->value, $oUser->oxuser__oxid->value, $oSimpleVoucher->fVoucherdiscount );
00984
00985 $this->_aVoucherList[$sVoucherId] = $oVoucher;
00986 }
00987 }
00988 }
00989
00995 public function save()
00996 {
00997 if ( ( $blSave = parent::save() ) ) {
00998
00999
01000 $oOrderArticles = $this->getOrderArticles();
01001 if ( $oOrderArticles && count( $oOrderArticles ) > 0 ) {
01002 foreach ( $oOrderArticles as $oOrderArticle ) {
01003 $oOrderArticle->save();
01004 }
01005 }
01006 }
01007
01008 return $blSave;
01009 }
01010
01017 public function getDelAddressInfo()
01018 {
01019 $oDelAdress = null;
01020 if ( ( $soxAddressId = oxConfig::getParameter( 'deladrid' ) ) ) {
01021 $oDelAdress = oxNew( 'oxaddress' );
01022 $oDelAdress->load( $soxAddressId );
01023
01024
01025 if ( $oDelAdress->oxaddress__oxcountryid->value && $oDelAdress->oxaddress__oxcountryid->value != -1 ) {
01026 $oCountry = oxNew( 'oxcountry' );
01027 $oCountry->load( $oDelAdress->oxaddress__oxcountryid->value );
01028 $oDelAdress->oxaddress__oxcountry = clone $oCountry->oxcountry__oxtitle;
01029 }
01030 }
01031 return $oDelAdress;
01032 }
01033
01044 public function validateStock( $oBasket )
01045 {
01046 foreach ( $oBasket->getContents() as $key => $oContent ) {
01047 try {
01048 $oProd = $oContent->getArticle();
01049 } catch ( oxNoArticleException $oEx ) {
01050 $oBasket->removeItem( $key );
01051 throw $oEx;
01052 } catch ( oxArticleInputException $oEx ) {
01053 $oBasket->removeItem( $key );
01054 throw $oEx;
01055 }
01056
01057
01058 $dArtStockAmount = $oBasket->getArtStockInBasket( $oProd->getId(), $key );
01059 $iOnStock = $oProd->checkForStock( $oContent->getAmount(), $dArtStockAmount );
01060 if ( $iOnStock !== true ) {
01061 $oEx = oxNew( 'oxOutOfStockException' );
01062 $oEx->setMessage( 'EXCEPTION_OUTOFSTOCK_OUTOFSTOCK' );
01063 $oEx->setArticleNr( $oProd->oxarticles__oxartnum->value );
01064 $oEx->setProductId( $oProd->getId() );
01065 $oEx->setRemainingAmount( $oProd->oxarticles__oxstock->value );
01066 throw $oEx;
01067 }
01068 }
01069 }
01070
01076 protected function _insert()
01077 {
01078 $myConfig = $this->getConfig();
01079 $oUtilsDate = oxUtilsDate::getInstance();
01080
01081
01082 if ( !$this->oxorder__oxorderdate->value ) {
01083 $this->oxorder__oxorderdate = new oxField(date( 'Y-m-d H:i:s', $oUtilsDate->getTime() ), oxField::T_RAW);
01084 } else {
01085 $this->oxorder__oxorderdate = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxorderdate->value, true ));
01086 }
01087 $this->oxorder__oxshopid = new oxField($myConfig->getShopId(), oxField::T_RAW);
01088
01089 $this->oxorder__oxsenddate = new oxField( $oUtilsDate->formatDBDate( $this->oxorder__oxsenddate->value, true ));
01090
01091 if ( ( $blInsert = parent::_insert() ) ) {
01092
01093 if ( !$this->oxorder__oxordernr->value ) {
01094 $aWhere = '';
01095
01096 if ( $this->_blSeparateNumbering ) {
01097 $aWhere = array( 'oxshopid = "'.$myConfig->getShopId().'"' );
01098 }
01099 $this->_setRecordNumber( 'oxordernr', $aWhere );
01100 }
01101 }
01102 return $blInsert;
01103 }
01104
01110 protected function _update()
01111 {
01112 $this->oxorder__oxsenddate = new oxField(oxUtilsDate::getInstance()->formatDBDate( $this->oxorder__oxsenddate->value, true ));
01113 return parent::_update();
01114 }
01115
01124 public function delete( $sOxId = null )
01125 {
01126 if ( $sOxId ) {
01127 if ( !$this->load( $sOxId ) ) {
01128
01129 return false;
01130 }
01131 } elseif ( !$sOxId ) {
01132 $sOxId = $this->getId();
01133 }
01134
01135
01136 if ( !$sOxId ) {
01137 return false;
01138 }
01139
01140
01141
01142 $oOrderArticles = $this->getOrderArticles( false );
01143 foreach ( $oOrderArticles as $oOrderArticle ) {
01144 $oOrderArticle->delete();
01145 }
01146
01147
01148 if ( $oPaymentType = $this->getPaymentType() ) {
01149 $oPaymentType->delete();
01150 }
01151
01152 return parent::delete( $sOxId );
01153 }
01154
01164 public function recalculateOrder( $aNewArticles = array() )
01165 {
01166 oxDb::startTransaction();
01167
01168 try {
01169 $oBasket = $this->_getOrderBasket();
01170
01171
01172 $this->_addOrderArticlesToBasket( $oBasket, $this->getOrderArticles( true ) );
01173
01174
01175 $this->_addArticlesToBasket( $oBasket, $aNewArticles );
01176
01177
01178 $oBasket->calculateBasket( true );
01179
01180
01181 $iRet = $this->finalizeOrder( $oBasket, $this->getOrderUser(), true );
01182
01183
01184 if ( $iRet !== 1 ) {
01185 oxDb::rollbackTransaction();
01186 } else {
01187 oxDb::commitTransaction();
01188 }
01189
01190 } catch( Exception $oE ) {
01191
01192 oxDb::rollbackTransaction();
01193
01194 if ( defined( 'OXID_PHP_UNIT' ) ) {
01195 throw $oE;
01196 }
01197 }
01198 }
01199
01200 protected $_oOrderBasket = null;
01208 protected function _getOrderBasket( $blStockCheck = true )
01209 {
01210 $this->_oOrderBasket = oxNew( "oxbasket" );
01211
01212
01213 $this->_oOrderBasket->setStockCheckMode( $blStockCheck );
01214
01215
01216 $this->_oOrderBasket->setBasketUser( $this->getOrderUser() );
01217
01218
01219 $this->_oOrderBasket->setOrderId( $this->getId() );
01220
01221
01222 $aCurrencies = $this->getConfig()->getCurrencyArray();
01223 foreach ( $aCurrencies as $oCur ) {
01224 if ($oCur->name == $this->oxorder__oxcurrency->value) {
01225 $oBasketCur = $oCur;
01226 break;
01227 }
01228 }
01229
01230
01231 $this->_oOrderBasket->setBasketCurrency( $oBasketCur );
01232
01233
01234 $this->_oOrderBasket->setCardId( $this->oxorder__oxcardid->value );
01235 $this->_oOrderBasket->setCardMessage( $this->oxorder__oxcardtext->value );
01236
01237 if ( $this->_blReloadDiscount ) {
01238
01239 $this->_oOrderBasket->setSkipVouchersChecking( true );
01240
01241
01242 $sQ = 'select oxid from oxvouchers where oxorderid = "'.$this->getId().'"';
01243 $aVouchers = oxDb::getDb( true )->getAll( $sQ );
01244 foreach ( $aVouchers as $aVoucher ) {
01245 $this->_oOrderBasket->addVoucher( $aVoucher['oxid'] );
01246 }
01247 } else {
01248 $this->_oOrderBasket->setDiscountCalcMode( false );
01249 $this->_oOrderBasket->setVoucherDiscount( $this->oxorder__oxvoucherdiscount->value );
01250 $this->_oOrderBasket->setTotalDiscount( $this->oxorder__oxdiscount->value );
01251 }
01252
01253
01254 if ( !$this->_blReloadDelivery ) {
01255 $this->_oOrderBasket->setDeliveryPrice( $this->getOrderDeliveryPrice() );
01256 } else {
01257
01258 $this->_oOrderBasket->setShipping( $this->oxorder__oxdeltype->value );
01259 $this->_oOrderBasket->setDeliveryPrice( null );
01260 }
01261
01262
01263 $this->_oOrderBasket->setPayment( $this->oxorder__oxpaymenttype->value );
01264
01265 return $this->_oOrderBasket;
01266 }
01267
01276 public function setDelivery( $sDeliveryId )
01277 {
01278 $this->reloadDelivery( true );
01279 $this->oxorder__oxdeltype = new oxField( $sDeliveryId );
01280 }
01281
01287 public function getOrderUser()
01288 {
01289 if ($this->_oUser === null ) {
01290 $this->_oUser = oxNew( "oxuser" );
01291 $this->_oUser->load( $this->oxorder__oxuserid->value );
01292
01293
01294 if ( $this->_isLoaded ) {
01295
01296 $this->_oUser->oxuser__oxcompany = clone $this->oxorder__oxbillcompany;
01297 $this->_oUser->oxuser__oxusername = clone $this->oxorder__oxbillemail;
01298 $this->_oUser->oxuser__oxfname = clone $this->oxorder__oxbillfname;
01299 $this->_oUser->oxuser__oxlname = clone $this->oxorder__oxbilllname;
01300 $this->_oUser->oxuser__oxstreet = clone $this->oxorder__oxbillstreet;
01301 $this->_oUser->oxuser__oxstreetnr = clone $this->oxorder__oxbillstreetnr;
01302 $this->_oUser->oxuser__oxaddinfo = clone $this->oxorder__oxbilladdinfo;
01303 $this->_oUser->oxuser__oxustid = clone $this->oxorder__oxbillustid;
01304
01305
01306 $this->_oUser->oxuser__oxcity = clone $this->oxorder__oxbillcity;
01307 $this->_oUser->oxuser__oxcountryid = clone $this->oxorder__oxbillcountryid;
01308 $this->_oUser->oxuser__oxstateid = clone $this->oxorder__oxbillstateid;
01309 $this->_oUser->oxuser__oxzip = clone $this->oxorder__oxbillzip;
01310 $this->_oUser->oxuser__oxfon = clone $this->oxorder__oxbillfon;
01311 $this->_oUser->oxuser__oxfax = clone $this->oxorder__oxbillfax;
01312 $this->_oUser->oxuser__oxsal = clone $this->oxorder__oxbillsal;
01313 }
01314 }
01315
01316 return $this->_oUser;
01317 }
01318
01326 public function pdfFooter( $oPdf )
01327 {
01328 }
01329
01337 public function pdfHeaderplus( $oPdf )
01338 {
01339 }
01340
01348 public function pdfHeader( $oPdf )
01349 {
01350 }
01351
01360 public function genPdf( $sFilename, $iSelLang = 0 )
01361 {
01362 }
01363
01369 public function getInvoiceNum()
01370 {
01371 $sQ = 'select max(oxorder.oxinvoicenr) from oxorder where oxorder.oxshopid = "'.$this->getConfig()->getShopId().'" ';
01372 return ( ( int ) oxDb::getDb()->getOne( $sQ ) + 1 );
01373 }
01374
01380 public function getNextBillNum()
01381 {
01382 $sQ = 'select max(cast(oxorder.oxbillnr as unsigned)) from oxorder where oxorder.oxshopid = "'.$this->getConfig()->getShopId().'" ';
01383 return ( ( int ) oxDb::getDb()->getOne( $sQ ) + 1 );
01384 }
01385
01391 public function getShippingSetList()
01392 {
01393
01394 if ( !( $sShipId = $this->oxorder__oxdelcountryid->value ) ) {
01395 $sShipId = $this->oxorder__oxbillcountryid->value;
01396 }
01397
01398 $oBasket = $this->_getOrderBasket( false );
01399
01400
01401 $this->_addOrderArticlesToBasket( $oBasket, $this->getOrderArticles() );
01402
01403
01404 $oBasket->calculateBasket( true );
01405
01406
01407 $oDeliveryList = oxNew( "oxDeliveryList", "core" );
01408 $oDeliveryList->setCollectFittingDeliveriesSets( true );
01409
01410 return $oDeliveryList->getDeliveryList( $oBasket, $this->getOrderUser(), $sShipId );
01411 }
01412
01418 public function getVoucherNrList()
01419 {
01420 $oDB = oxDb::getDb( true );
01421 $aVouchers = array();
01422 $sSelect = "select oxvouchernr from oxvouchers where oxorderid = ".$oDB->quote( $this->oxorder__oxid->value );
01423 $rs = $oDB->execute( $sSelect);
01424 if ($rs != false && $rs->recordCount() > 0) {
01425 while (!$rs->EOF) {
01426 $aVouchers[] = $rs->fields['oxvouchernr'];
01427 $rs->moveNext();
01428 }
01429 }
01430 return $aVouchers;
01431 }
01432
01440 public function getOrderSum( $blToday = false )
01441 {
01442 $sSelect = 'select sum(oxtotalordersum / oxcurrate) from oxorder where ';
01443 $sSelect .= 'oxshopid = "'.$this->getConfig()->getShopId().'" and oxorder.oxstorno != "1" ';
01444
01445 if ( $blToday ) {
01446 $sSelect .= 'and oxorderdate like "'.date( 'Y-m-d').'%" ';
01447 }
01448
01449 return ( double ) oxDb::getDb()->getOne( $sSelect );
01450 }
01451
01459 public function getOrderCnt( $blToday = false )
01460 {
01461 $sSelect = 'select count(*) from oxorder where ';
01462 $sSelect .= 'oxshopid = "'.$this->getConfig()->getShopId().'" and oxorder.oxstorno != "1" ';
01463
01464 if ( $blToday ) {
01465 $sSelect .= 'and oxorderdate like "'.date( 'Y-m-d').'%" ';
01466 }
01467
01468 return ( int ) oxDb::getDb()->getOne( $sSelect );
01469 }
01470
01471
01479 protected function _checkOrderExist( $sOxId = null )
01480 {
01481 if ( !$sOxId) {
01482 return false;
01483 }
01484
01485 $oDb = oxDb::getDb();
01486 if ( $oDb->getOne( 'select oxid from oxorder where oxid = '.$oDb->quote( $sOxId ) ) ) {
01487 return true;
01488 }
01489
01490 return false;
01491 }
01492
01502 protected function _sendOrderByEmail( $oUser = null, $oBasket = null, $oPayment = null )
01503 {
01504 $iRet = self::ORDER_STATE_MAILINGERROR;
01505
01506
01507 $this->_oUser = $oUser;
01508 $this->_oBasket = $oBasket;
01509 $this->_oPayment = $oPayment;
01510
01511 $oxEmail = oxNew( 'oxemail' );
01512
01513
01514 if ( $oxEmail->sendOrderEMailToUser( $this ) ) {
01515
01516 $iRet = self::ORDER_STATE_OK;
01517 }
01518
01519
01520 $oxEmail->sendOrderEMailToOwner( $this );
01521
01522 return $iRet;
01523 }
01524
01530 public function getBasket()
01531 {
01532 return $this->_oBasket;
01533 }
01534
01540 public function getPayment()
01541 {
01542 return $this->_oPayment;
01543 }
01544
01550 public function getVoucherList()
01551 {
01552 return $this->_aVoucherList;
01553 }
01554
01560 public function getDelSet()
01561 {
01562 if ( $this->_oDelSet == null ) {
01563
01564 $this->_oDelSet = oxNew( 'oxdeliveryset' );
01565 $this->_oDelSet->load( $this->oxorder__oxdeltype->value );
01566 }
01567
01568 return $this->_oDelSet;
01569 }
01570
01576 public function getPaymentType()
01577 {
01578 if ( $this->oxorder__oxpaymentid->value && $this->_oPaymentType === null ) {
01579 $this->_oPaymentType = false;
01580 $oPaymentType = oxNew( 'oxuserpayment' );
01581 if ( $oPaymentType->load( $this->oxorder__oxpaymentid->value ) ) {
01582 $this->_oPaymentType = $oPaymentType;
01583 }
01584 }
01585
01586 return $this->_oPaymentType;
01587 }
01588
01594 public function getGiftCard()
01595 {
01596 if ( $this->oxorder__oxcardid->value && $this->_oGiftCard == null ) {
01597 $this->_oGiftCard = oxNew( 'oxwrapping' );
01598 $this->_oGiftCard->load( $this->oxorder__oxcardid->value );
01599 }
01600
01601 return $this->_oGiftCard;
01602 }
01603
01611 public function setSeparateNumbering( $blSeparateNumbering = null )
01612 {
01613 $this->_blSeparateNumbering = $blSeparateNumbering;
01614 }
01615
01623 public function getLastUserPaymentType( $sUserId)
01624 {
01625 $oDb = oxDb::getDb();
01626 $sQ = 'select oxorder.oxpaymenttype from oxorder where oxorder.oxshopid="'.$this->getConfig()->getShopId().'" and oxorder.oxuserid='.$oDb->quote( $sUserId ).' order by oxorder.oxorderdate desc ';
01627 $sLastPaymentId = $oDb->getOne( $sQ );
01628 return $sLastPaymentId;
01629 }
01630
01643 protected function _makeSelListArray( $sArtId = null, $sOrderArtSelList = null )
01644 {
01645 $oOrder = oxNew( 'oxorderArticle' );
01646 return $oOrder->getOrderArticleSelectList( $sArtId, $sOrderArtSelList );
01647 }
01648
01657 protected function _addOrderArticlesToBasket( $oBasket, $aOrderArticles )
01658 {
01659
01660 if ( count( $aOrderArticles ) > 0 ) {
01661
01662
01663 foreach ( $aOrderArticles as $oOrderArticle ) {
01664 $oBasket->addOrderArticleToBasket( $oOrderArticle );
01665 }
01666 }
01667 }
01668
01677 protected function _addArticlesToBasket( $oBasket, $aArticles )
01678 {
01679
01680 if ( count($aArticles ) > 0 ) {
01681
01682
01683 foreach ( $aArticles as $oArticle ) {
01684 $aSel = isset( $oArticle->oxorderarticles__oxselvariant ) ? $oArticle->oxorderarticles__oxselvariant->value : null;
01685 $aPersParam = isset( $oArticle->oxorderarticles__oxpersparam ) ? $oArticle->getPersParams() : null;
01686 $oBasket->addToBasket( $oArticle->oxorderarticles__oxartid->value,
01687 $oArticle->oxorderarticles__oxamount->value,
01688 $aSel, $aPersParam );
01689 }
01690 }
01691 }
01692
01700 protected function _setDeprecatedValues()
01701 {
01702 if ( $this->oxorder__oxstorno->value != 1 ) {
01703 $oCur = $this->getConfig()->getActShopCurrencyObject();
01704 $oLang = oxLang::getInstance();
01705
01706 $this->totalnetsum = $this->oxorder__oxtotalnetsum->value;
01707 $this->totalbrutsum = $this->oxorder__oxtotalbrutsum->value;
01708 $this->totalorder = $this->oxorder__oxtotalordersum->value;
01709 $this->ftotalnetsum = $oLang->formatCurrency( $this->oxorder__oxtotalnetsum->value, $oCur );
01710 $this->ftotalbrutsum = $oLang->formatCurrency( $this->oxorder__oxtotalbrutsum->value, $oCur );
01711 $this->fdelcost = $oLang->formatCurrency( $this->oxorder__oxdelcost->value, $oCur );
01712 $this->fpaycost = $oLang->formatCurrency( $this->oxorder__oxpaycost->value, $oCur );
01713 $this->fwrapcost = $oLang->formatCurrency( $this->oxorder__oxwrapcost->value, $oCur );
01714 $this->ftotalorder = $this->getTotalOrderSum();
01715 $this->totalvouchers = 0;
01716
01717 if ( $this->oxorder__oxvoucherdiscount->value ) {
01718 $this->totalvouchers = $oLang->formatCurrency( $this->oxorder__oxvoucherdiscount->value, $oCur );
01719 }
01720
01721 if ( $this->oxorder__oxdiscount->value ) {
01722 $this->discount = $this->oxorder__oxdiscount->value;
01723 $this->fdiscount = $oLang->formatCurrency( $this->oxorder__oxdiscount->value, $oCur );
01724 }
01725 }
01726 }
01727
01733 public function getTotalOrderSum()
01734 {
01735 $oCur = $this->getConfig()->getActShopCurrencyObject();
01736 return number_format( (double)$this->oxorder__oxtotalordersum->value, $oCur->decimal, '.', '');
01737 }
01738
01746 public function getProductVats( $blFormatCurrency = true )
01747 {
01748 $aVats = array();
01749 if ($this->oxorder__oxartvat1->value) {
01750 $aVats[$this->oxorder__oxartvat1->value] = $this->oxorder__oxartvatprice1->value;
01751 }
01752 if ($this->oxorder__oxartvat2->value) {
01753 $aVats[$this->oxorder__oxartvat2->value] = $this->oxorder__oxartvatprice2->value;
01754 }
01755
01756 if ( $blFormatCurrency ) {
01757 $oLang = oxLang::getInstance();
01758 $oCur = $this->getConfig()->getActShopCurrencyObject();
01759 foreach ( $aVats as $sKey => $dVat ) {
01760 $aVats[$sKey] = $oLang->formatCurrency( $dVat, $oCur );
01761 }
01762 }
01763 return $aVats;
01764 }
01765
01771 public function getBillCountry()
01772 {
01773 if ( !$this->oxorder__oxbillcountry->value ) {
01774 $this->oxorder__oxbillcountry = new oxField($this->_getCountryTitle( $this->oxorder__oxbillcountryid->value ));
01775 }
01776 return $this->oxorder__oxbillcountry;
01777 }
01778
01784 public function getDelCountry()
01785 {
01786 if ( !$this->oxorder__oxdelcountry->value ) {
01787 $this->oxorder__oxdelcountry = new oxField($this->_getCountryTitle( $this->oxorder__oxdelcountryid->value ));
01788 }
01789 return $this->oxorder__oxdelcountry;
01790 }
01798 public function reloadDelivery( $blReload )
01799 {
01800 $this->_blReloadDelivery = $blReload;
01801 }
01802
01810 public function reloadDiscount( $blReload )
01811 {
01812 $this->_blReloadDiscount = $blReload;
01813 }
01814
01820 public function cancelOrder()
01821 {
01822 $this->oxorder__oxstorno = new oxField( 1 );
01823 if ( $this->save() ) {
01824
01825 foreach ( $this->getOrderArticles() as $oOrderArticle ) {
01826 $oOrderArticle->cancelOrderArticle();
01827 }
01828 }
01829 }
01830
01837 public function getOrderCurrency()
01838 {
01839 if ( $this->_oOrderCurrency === null ) {
01840
01841
01842 $aCurrencies = $this->getConfig()->getCurrencyArray();
01843 $this->_oOrderCurrency = current( $aCurrencies );
01844
01845 foreach ( $aCurrencies as $oCurr ) {
01846 if ( $oCurr->name == $this->oxorder__oxcurrency->value ) {
01847 $this->_oOrderCurrency = $oCurr;
01848 break;
01849 }
01850 }
01851 }
01852 return $this->_oOrderCurrency;
01853 }
01854
01864 public function validateOrder( $oBasket, $oUser )
01865 {
01866
01867 $iValidState = $this->validateStock( $oBasket );
01868
01869 if ( !$iValidState ) {
01870
01871 $iValidState = $this->validateDelivery( $oBasket );
01872 }
01873
01874 if ( !$iValidState ) {
01875
01876 $iValidState = $this->validatePayment( $oBasket );
01877 }
01878
01879 return $iValidState;
01880 }
01881
01890 public function validateDelivery( $oBasket )
01891 {
01892
01893
01894 if ( $oBasket->getPaymentId() == 'oxempty') {
01895 return;
01896 }
01897 $oDb = oxDb::getDb();
01898
01899 $oDelSet = oxNew( "oxdeliveryset" );
01900 $sTable = $oDelSet->getViewName();
01901
01902 $sQ = "select 1 from {$sTable} where {$sTable}.oxid=".
01903 $oDb->quote( $oBasket->getShippingId() )." and ".$oDelSet->getSqlActiveSnippet();
01904
01905 if ( !$oDb->getOne( $sQ ) ) {
01906
01907 return self::ORDER_STATE_INVALIDDELIVERY;
01908 }
01909 }
01910
01919 public function validatePayment( $oBasket )
01920 {
01921 $oDb = oxDb::getDb();
01922
01923 $oPayment = oxNew( "oxpayment" );
01924 $sTable = $oPayment->getViewName();
01925
01926 $sQ = "select 1 from {$sTable} where {$sTable}.oxid=".
01927 $oDb->quote( $oBasket->getPaymentId() )." and ".$oPayment->getSqlActiveSnippet();
01928
01929 if ( !$oDb->getOne( $sQ ) ) {
01930 return self::ORDER_STATE_INVALIDPAYMENT;
01931 }
01932 }
01933 }