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 }
00054
00055 return "order_article.tpl";
00056 }
00057
00063 public function getEditObject()
00064 {
00065 $soxId = oxConfig::getParameter( "oxid" );
00066 if ( $this->_oEditObject === null && isset( $soxId ) && $soxId != "-1" ) {
00067 $this->_oEditObject = oxNew( "oxorder" );
00068 $this->_oEditObject->load( $soxId );
00069 }
00070 return $this->_oEditObject;
00071 }
00072
00078 public function getSearchProductArtNr()
00079 {
00080 return oxConfig::getParameter( 'sSearchArtNum' );
00081 }
00082
00088 public function getSearchProduct()
00089 {
00090 if ( $this->_oSearchProduct === null ) {
00091 $this->_oSearchProduct = false;
00092 $sSearchArtNum = $this->getSearchProductArtNr();
00093
00094 foreach ( $this->getProductList() as $oProduct ) {
00095 if ( $oProduct->oxarticles__oxartnum->value == $sSearchArtNum ) {
00096 $this->_oSearchProduct = $oProduct;
00097 break;
00098 }
00099 }
00100 }
00101
00102 return $this->_oSearchProduct;
00103 }
00104
00110 public function getMainProduct()
00111 {
00112 if ( $this->_oMainSearchProduct === null && ( $sArtNum = $this->getSearchProductArtNr() ) ) {
00113 $this->_oMainSearchProduct = false;
00114 $sArtId = null;
00115
00116
00117 $oDb = oxDb::getDb(true);
00118 $sQ = "select oxid, oxparentid from oxarticles where oxarticles.oxartnum = ".$oDb->quote( $sArtNum )." limit 1";
00119 $rs = $oDb->execute( $sQ );
00120 if ($rs != false && $rs->recordCount() > 0) {
00121 $sArtId = $rs->fields['oxparentid'] ? $rs->fields['oxparentid'] : $rs->fields['oxid'];
00122 $oProduct = oxNew( "oxarticle" );
00123 if ( $oProduct->load( $sArtId ) ) {
00124 $this->_oMainSearchProduct = $oProduct;
00125 }
00126 }
00127 }
00128
00129 return $this->_oMainSearchProduct;
00130 }
00131
00137 public function getProductList()
00138 {
00139 if ( $this->_oSearchProductList === null ) {
00140 $this->_oSearchProductList = oxNew( "oxlist" );
00141
00142
00143 if ( $oMainSearchProduct = $this->getMainProduct() ) {
00144
00145 $this->_oSearchProductList->offsetSet( $oMainSearchProduct->getId(), $oMainSearchProduct );
00146
00147
00148 foreach ( $oMainSearchProduct->getVariants() as $oVariant ) {
00149 $this->_oSearchProductList->offsetSet( $oVariant->getId(), $oVariant );
00150 }
00151 }
00152 }
00153
00154 return $this->_oSearchProductList;
00155 }
00156
00162 public function addThisArticle()
00163 {
00164 $sOxid = oxConfig::getParameter( 'aid' );
00165 $dAmount = oxConfig::getParameter( 'am' );
00166 $oProduct = oxNew( "oxarticle" );
00167
00168 if ( $sOxid && $dAmount && $oProduct->load( $sOxid ) ) {
00169
00170 $sOrderId = oxConfig::getParameter( 'oxid' );
00171 $oOrder = oxNew( 'oxorder' );
00172 if ( $sOrderId && $oOrder->load( $sOrderId ) ) {
00173
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
00180 $oOrder->recalculateOrder( array( $oOrderArticle ) );
00181 }
00182 }
00183 }
00184
00190 public function deleteThisArticle()
00191 {
00192
00193 $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00194 $sOrderId = oxConfig::getParameter( 'oxid' );
00195
00196 $oOrderArticle = oxNew( 'oxorderarticle' );
00197 $oOrder = oxNew( 'oxorder' );
00198
00199
00200 if ( $oOrderArticle->load( $sOrderArtId ) && $oOrder->load( $sOrderId ) ) {
00201 $myConfig = $this->getConfig();
00202
00203
00204 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00205 $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value, $myConfig->getConfigParam('blAllowNegativeStock') );
00206 }
00207
00208
00209 $oOrderArticle->delete();
00210
00211
00212 $oOrder->recalculateOrder();
00213 }
00214 }
00215
00221 public function storno()
00222 {
00223 $myConfig = $this->getConfig();
00224
00225 $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00226 $oArticle = oxNew( 'oxorderarticle' );
00227 $oArticle->load( $sOrderArtId );
00228
00229 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00230 $oArticle->oxorderarticles__oxstorno->setValue( 0 );
00231 $sStockSign = -1;
00232 } else {
00233 $oArticle->oxorderarticles__oxstorno->setValue( 1 );
00234 $sStockSign = 1;
00235 }
00236
00237
00238 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00239 $oArticle->updateArticleStock( $oArticle->oxorderarticles__oxamount->value * $sStockSign, $myConfig->getConfigParam('blAllowNegativeStock') );
00240 }
00241
00242 $oDb = oxDb::getDb();
00243 $sQ = "update oxorderarticles set oxstorno = ".$oDb->quote( $oArticle->oxorderarticles__oxstorno->value )." where oxid = ".$oDb->quote( $sOrderArtId );
00244 $oDb->execute( $sQ );
00245
00246
00247 $sQ = "select oxartid from oxorderarticles where oxid = ".$oDb->quote( $sOrderArtId );
00248 if ( ( $sArtId = oxDb::getDb()->getOne( $sQ ) ) ) {
00249 $oOrder = oxNew( 'oxorder' );
00250 if ( $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00251 $oOrder->recalculateOrder();
00252 }
00253 }
00254 }
00255
00261 public function updateOrder()
00262 {
00263 $aOrderArticles = oxConfig::getParameter( 'aOrderArticles' );
00264
00265 $oOrder = oxNew( 'oxorder' );
00266 if ( is_array( $aOrderArticles ) && $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00267
00268 $myConfig = $this->getConfig();
00269 $oOrderArticles = $oOrder->getOrderArticles();
00270
00271 $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00272 foreach ( $oOrderArticles as $oOrderArticle ) {
00273 $sItemId = $oOrderArticle->getId();
00274 if ( isset( $aOrderArticles[$sItemId] ) ) {
00275
00276
00277 if ( $blUseStock ) {
00278 $oOrderArticle->setNewAmount( $aOrderArticles[$sItemId]['oxamount'] );
00279 } else {
00280 $oOrderArticle->assign( $aOrderArticles[$sItemId] );
00281 $oOrderArticle->save();
00282 }
00283 }
00284 }
00285
00286
00287 $oOrder->recalculateOrder();
00288 }
00289 }
00290 }