order_main.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Order_Main extends oxAdminDetails
00009 {
00017     public function render()
00018     {
00019         parent::render();
00020 
00021         $soxId = oxConfig::getParameter( "oxid");
00022         // check if we right now saved a new entry
00023         $sSavedID = oxConfig::getParameter( "saved_oxid");
00024         if ( ($soxId == "-1" || !isset( $soxId)) && isset( $sSavedID) ) {
00025             $soxId = $sSavedID;
00026             oxSession::deleteVar( "saved_oxid");
00027             $this->_aViewData["oxid"] =  $soxId;
00028             // for reloading upper frame
00029             $this->_aViewData["updatelist"] =  "1";
00030         }
00031 
00032         if ( $soxId != "-1" && isset( $soxId ) ) {
00033             // load object
00034             $oOrder = oxNew( "oxorder" );
00035             $oOrder->load( $soxId);
00036 
00037             // paid ?
00038             if ( $oOrder->oxorder__oxpaid->value != "0000-00-00 00:00:00") {
00039                 $oOrder->blIsPaid = true;
00040                 $oOrder->oxorder__oxpaid = new oxField( oxUtilsDate::getInstance()->formatDBDate( $oOrder->oxorder__oxpaid->value ) );
00041             }
00042 
00043             $this->_aViewData["edit"] =  $oOrder;
00044             $this->_aViewData["paymentType"] =  $oOrder->getPaymentType();
00045 
00046             $this->_aViewData["oShipSet"] =  $oOrder->getShippingSetList();
00047             if ( $oOrder->oxorder__oxdeltype->value ) {
00048 
00049                 // order user
00050                 $oUser = oxNew( 'oxuser' );
00051                 $oUser->load( $oOrder->oxorder__oxuserid->value );
00052 
00053                 // order sum in default currency
00054                 $dPrice = $oOrder->oxorder__oxtotalbrutsum->value / $oOrder->oxorder__oxcurrate->value;
00055 
00056                 $this->_aViewData["oPayments"] = oxPaymentList::getInstance()->getPaymentList( $oOrder->oxorder__oxdeltype->value, $dPrice, $oUser );
00057             }
00058 
00059             // any voucher used ?
00060             $this->_aViewData["aVouchers"] =  $oOrder->getVoucherNrList();
00061         }
00062 
00063         $this->_aViewData["sNowValue"] = date("Y-m-d H:i:s", oxUtilsDate::getInstance()->getTime());
00064         return "order_main.tpl";
00065     }
00066 
00072     public function save()
00073     {
00074 
00075         $soxId      = oxConfig::getParameter( "oxid" );
00076         $aParams    = oxConfig::getParameter( "editval" );
00077 
00078             // shopid
00079             $sShopID = oxSession::getVar( "actshop" );
00080             $aParams['oxorder__oxshopid'] = $sShopID;
00081 
00082         $oOrder = oxNew( "oxorder" );
00083         if ( $soxId != "-1") {
00084             $oOrder->load( $soxId);
00085         } else {
00086             $aParams['oxorder__oxid'] = null;
00087         }
00088 
00089         $oOrder->assign( $aParams);
00090 
00091         $aDynvalues = oxConfig::getParameter( "dynvalue" );
00092         if ( isset( $aDynvalues ) ) {
00093             // #411 Dodger
00094             $oPayment = oxNew( "oxuserpayment" );
00095             $oPayment->load( $oOrder->oxorder__oxpaymentid->value);
00096             $oPayment->oxuserpayments__oxvalue->setValue(oxUtils::getInstance()->assignValuesToText( $aDynvalues));
00097             $oPayment->save();
00098         }
00099 
00100         // keeps old delivery cost
00101         $oOrder->reloadDelivery( false );
00102 
00103         // keeps old discount
00104         $oOrder->reloadDiscount( false );
00105 
00106         $oOrder->recalculateOrder();
00107 
00108         // set oxid if inserted
00109         if ( $soxId == "-1" ) {
00110             oxSession::setVar( "saved_oxid", $oOrder->oxorder__oxid->value );
00111         }
00112 
00113         // reloading upper frame
00114         $this->_aViewData["updatelist"] = "1";
00115     }
00116 
00122     public function sendorder()
00123     {
00124         $soxId  = oxConfig::getParameter( "oxid" );
00125         $oOrder = oxNew( "oxorder" );
00126         if ( $oOrder->load( $soxId ) ) {
00127 
00128             // #632A
00129             $oOrder->oxorder__oxsenddate->setValue( date( "Y-m-d H:i:s", oxUtilsDate::getInstance()->getTime() ) );
00130             $oOrder->save();
00131 
00132             // #1071C
00133             $oOrderArticles = $oOrder->getOrderArticles();
00134             foreach ( $oOrderArticles as $sOxId => $oArticle ) {
00135                 // remove canceled articles from list
00136                 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00137                     $oOrderArticles->offsetUnset( $sOxId );
00138                 }
00139             }
00140 
00141             if ( oxConfig::getParameter( "sendmail" ) ) {
00142                 // send eMail
00143                 $oEmail = oxNew( "oxemail" );
00144                 $oEmail->sendSendedNowMail( $oOrder );
00145             }
00146 
00147         }
00148     }
00149 
00155     public function resetorder()
00156     {
00157         $oOrder = oxNew( "oxorder" );
00158         if ( $oOrder->load( oxConfig::getParameter( "oxid") ) ) {
00159 
00160             $oOrder->oxorder__oxsenddate->setValue("0000-00-00 00:00:00");
00161             $oOrder->save();
00162 
00163         }
00164     }
00165 
00172     public function changeDelSet()
00173     {
00174         $oOrder = oxNew( "oxorder" );
00175         if ( ( $sDelSetId = oxConfig::getParameter( "setDelSet" ) ) &&
00176              $oOrder->load( oxConfig::getParameter( "oxid" ) ) ) {
00177             $oOrder->oxorder__oxpaymenttype->setValue( "oxempty" );
00178             // keeps old discount
00179             $oOrder->reloadDiscount( false );
00180             $oOrder->setDelivery( $sDelSetId );
00181             $oOrder->recalculateOrder();
00182         }
00183     }
00184 
00191     public function changePayment()
00192     {
00193         $oOrder = oxNew( "oxorder" );
00194         if ( ( $sPayId = oxConfig::getParameter( "setPayment") ) &&
00195              $oOrder->load( oxConfig::getParameter( "oxid" ) ) ) {
00196             $oOrder->oxorder__oxpaymenttype->setValue( $sPayId );
00197             // keeps old discount
00198             $oOrder->reloadDiscount( false );
00199             $oOrder->recalculateOrder();
00200         }
00201     }
00202 }