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 $oOrderArticle->delete();
00205
00206
00207 $oOrder->recalculateOrder();
00208 }
00209 }
00210
00216 public function storno()
00217 {
00218 $myConfig = $this->getConfig();
00219
00220 $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00221 $oArticle = oxNew( 'oxorderarticle' );
00222 $oArticle->load( $sOrderArtId );
00223
00224 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00225 $oArticle->oxorderarticles__oxstorno->setValue( 0 );
00226 $sStockSign = -1;
00227 } else {
00228 $oArticle->oxorderarticles__oxstorno->setValue( 1 );
00229 $sStockSign = 1;
00230 }
00231
00232
00233 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00234 $oArticle->updateArticleStock( $oArticle->oxorderarticles__oxamount->value * $sStockSign, $myConfig->getConfigParam('blAllowNegativeStock') );
00235 }
00236
00237 $oDb = oxDb::getDb();
00238 $sQ = "update oxorderarticles set oxstorno = ".$oDb->quote( $oArticle->oxorderarticles__oxstorno->value )." where oxid = ".$oDb->quote( $sOrderArtId );
00239 $oDb->execute( $sQ );
00240
00241
00242 $sQ = "select oxartid from oxorderarticles where oxid = ".$oDb->quote( $sOrderArtId );
00243 if ( ( $sArtId = oxDb::getDb()->getOne( $sQ ) ) ) {
00244 $oOrder = oxNew( 'oxorder' );
00245 if ( $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00246 $oOrder->recalculateOrder();
00247 }
00248 }
00249 }
00250
00256 public function updateOrder()
00257 {
00258 $aOrderArticles = oxConfig::getParameter( 'aOrderArticles' );
00259
00260 $oOrder = oxNew( 'oxorder' );
00261 if ( is_array( $aOrderArticles ) && $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00262
00263 $myConfig = $this->getConfig();
00264 $oOrderArticles = $oOrder->getOrderArticles();
00265
00266 $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00267 foreach ( $oOrderArticles as $oOrderArticle ) {
00268 $sItemId = $oOrderArticle->getId();
00269 if ( isset( $aOrderArticles[$sItemId] ) ) {
00270
00271
00272 if ( $blUseStock ) {
00273 $oOrderArticle->setNewAmount( $aOrderArticles[$sItemId]['oxamount'] );
00274 } else {
00275 $oOrderArticle->assign( $aOrderArticles[$sItemId] );
00276 $oOrderArticle->save();
00277 }
00278 }
00279 }
00280
00281
00282 $oOrder->recalculateOrder();
00283 }
00284 }
00285 }