order_article.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Order_Article extends oxAdminDetails
00009 {
00015     protected $_oSearchProduct = null;
00016 
00024     protected $_oSearchProductList = null;
00025 
00031     protected $_oMainSearchProduct = null;
00032 
00038     protected $_oEditObject = null;
00039 
00047     public function render()
00048     {
00049         parent::render();
00050 
00051         if ( $oOrder = $this->getEditObject() ) {
00052             $this->_aViewData["edit"] = $oOrder;
00053             $this->_aViewData["aProductVats"] = $oOrder->getProductVats();
00054         }
00055 
00056         return "order_article.tpl";
00057     }
00058 
00064     public function getEditObject()
00065     {
00066         $soxId = oxConfig::getParameter( "oxid" );
00067         if ( $this->_oEditObject === null && isset( $soxId ) && $soxId != "-1" ) {
00068             $this->_oEditObject = oxNew( "oxorder" );
00069             $this->_oEditObject->load( $soxId );
00070         }
00071         return $this->_oEditObject;
00072     }
00073 
00079     public function getSearchProductArtNr()
00080     {
00081         return oxConfig::getParameter( 'sSearchArtNum' );
00082     }
00083 
00089     public function getSearchProduct()
00090     {
00091         if ( $this->_oSearchProduct === null ) {
00092             $this->_oSearchProduct = false;
00093             $sSearchArtNum = $this->getSearchProductArtNr();
00094 
00095             foreach ( $this->getProductList() as $oProduct ) {
00096                 if ( $oProduct->oxarticles__oxartnum->value == $sSearchArtNum ) {
00097                     $this->_oSearchProduct = $oProduct;
00098                     break;
00099                 }
00100             }
00101         }
00102 
00103         return $this->_oSearchProduct;
00104     }
00105 
00111     public function getMainProduct()
00112     {
00113         if ( $this->_oMainSearchProduct === null && ( $sArtNum = $this->getSearchProductArtNr() ) ) {
00114             $this->_oMainSearchProduct = false;
00115             $sArtId = null;
00116 
00117             //get article id
00118             $oDb = oxDb::getDb(true);
00119             $sQ  = "select oxid, oxparentid from oxarticles where oxarticles.oxartnum = ".$oDb->quote( $sArtNum )." limit 1";
00120             $rs  = $oDb->execute( $sQ );
00121             if ($rs != false && $rs->recordCount() > 0) {
00122                 $sArtId = $rs->fields['oxparentid'] ? $rs->fields['oxparentid'] : $rs->fields['oxid'];
00123                 $oProduct = oxNew( "oxarticle" );
00124                 if ( $oProduct->load( $sArtId ) ) {
00125                     $this->_oMainSearchProduct = $oProduct;
00126                 }
00127             }
00128         }
00129 
00130         return $this->_oMainSearchProduct;
00131     }
00132 
00138     public function getProductList()
00139     {
00140         if ( $this->_oSearchProductList === null ) {
00141             $this->_oSearchProductList = oxNew( "oxlist" );
00142 
00143             // main search product is found?
00144             if ( $oMainSearchProduct = $this->getMainProduct() ) {
00145                 // storing self to first list position
00146                 $this->_oSearchProductList->offsetSet( $oMainSearchProduct->getId(), $oMainSearchProduct );
00147 
00148                 // adding variants..
00149                 foreach ( $oMainSearchProduct->getVariants() as $oVariant ) {
00150                     $this->_oSearchProductList->offsetSet( $oVariant->getId(), $oVariant );
00151                 }
00152             }
00153         }
00154 
00155         return $this->_oSearchProductList;
00156     }
00157 
00163     public function addThisArticle()
00164     {
00165         $sOxid    = oxConfig::getParameter( 'aid' );
00166         $dAmount  = oxConfig::getParameter( 'am' );
00167         $oProduct = oxNew( "oxarticle" );
00168 
00169         if ( $sOxid && $dAmount && $oProduct->load( $sOxid ) ) {
00170 
00171             $sOrderId = oxConfig::getParameter( 'oxid' );
00172             $oOrder   = oxNew( 'oxorder' );
00173             if ( $sOrderId && $oOrder->load( $sOrderId ) ) {
00174                 $oOrderArticle = oxNew( 'oxorderArticle' );
00175                 $oOrderArticle->oxorderarticles__oxartid  = new oxField( $oProduct->getId() );
00176                 $oOrderArticle->oxorderarticles__oxartnum = new oxField( $oProduct->oxarticles__oxartnum->value );
00177                 $oOrderArticle->oxorderarticles__oxamount = new oxField( $dAmount );
00178                 $oOrderArticle->oxorderarticles__oxselvariant = new oxField( oxConfig::getParameter( 'sel' ) );
00179                 $oOrder->recalculateOrder( array( $oOrderArticle ) );
00180             }
00181         }
00182     }
00183 
00189     public function deleteThisArticle()
00190     {
00191         // get article id
00192         $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00193         $sOrderId = oxConfig::getParameter( 'oxid' );
00194 
00195         $oOrderArticle = oxNew( 'oxorderarticle' );
00196         $oOrder = oxNew( 'oxorder' );
00197 
00198         // order and order article exits?
00199         if ( $oOrderArticle->load( $sOrderArtId ) && $oOrder->load( $sOrderId ) ) {
00200             $myConfig = $this->getConfig();
00201 
00202             // deleting record
00203             $oOrderArticle->delete();
00204 
00205             // recalculating order
00206             $oOrder->recalculateOrder();
00207         }
00208     }
00209 
00215     public function storno()
00216     {
00217         $myConfig = $this->getConfig();
00218 
00219         $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00220         $oArticle = oxNew( 'oxorderarticle' );
00221         $oArticle->load( $sOrderArtId );
00222 
00223         if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00224             $oArticle->oxorderarticles__oxstorno->setValue( 0 );
00225             $sStockSign = -1;
00226         } else {
00227             $oArticle->oxorderarticles__oxstorno->setValue( 1 );
00228             $sStockSign = 1;
00229         }
00230 
00231         // stock information
00232         if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00233             $oArticle->updateArticleStock( $oArticle->oxorderarticles__oxamount->value * $sStockSign, $myConfig->getConfigParam('blAllowNegativeStock') );
00234         }
00235 
00236         $oDb = oxDb::getDb();
00237         $sQ = "update oxorderarticles set oxstorno = ".$oDb->quote( $oArticle->oxorderarticles__oxstorno->value )." where oxid = ".$oDb->quote( $sOrderArtId );
00238         $oDb->execute( $sQ );
00239 
00240         //get article id
00241         $sQ = "select oxartid from oxorderarticles where oxid = ".$oDb->quote( $sOrderArtId );
00242         if ( ( $sArtId = oxDb::getDb()->getOne( $sQ ) ) ) {
00243             $oOrder = oxNew( 'oxorder' );
00244             if ( $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00245                 $oOrder->recalculateOrder();
00246             }
00247         }
00248     }
00249 
00255     public function updateOrder()
00256     {
00257         $aOrderArticles = oxConfig::getParameter( 'aOrderArticles' );
00258 
00259         $oOrder = oxNew( 'oxorder' );
00260         if ( is_array( $aOrderArticles ) && $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00261 
00262             $myConfig = $this->getConfig();
00263             $oOrderArticles = $oOrder->getOrderArticles();
00264 
00265             $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00266             foreach ( $oOrderArticles as $oOrderArticle ) {
00267                 $sItemId = $oOrderArticle->getId();
00268                 if ( isset( $aOrderArticles[$sItemId] ) ) {
00269 
00270                     // update stock
00271                     if ( $blUseStock ) {
00272                         $oOrderArticle->setNewAmount( $aOrderArticles[$sItemId]['oxamount'] );
00273                     } else {
00274                         $oOrderArticle->assign( $aOrderArticles[$sItemId] );
00275                         $oOrderArticle->save();
00276                     }
00277                 }
00278             }
00279 
00280             // recalculating order
00281             $oOrder->recalculateOrder();
00282         }
00283     }
00284 }

Generated by  doxygen 1.6.2