00001 <?php
00002
00008 class Order_Article extends oxAdminDetails
00009 {
00017 public function render()
00018 {
00019 parent::render();
00020
00021 $soxId = oxConfig::getParameter( "oxid" );
00022 if ( $soxId != "-1" && isset( $soxId ) ) {
00023
00024 $oOrder = oxNew( "oxorder" );
00025 $oOrder->load( $soxId );
00026
00027 $this->_aViewData["edit"] = $oOrder;
00028 }
00029
00030 return "order_article.tpl";
00031 }
00032
00038 public function addThisArticle()
00039 {
00040 if ( ( $sArtNum = oxConfig::getParameter( 'sArtNum' ) ) ) {
00041 $dAmount = oxConfig::getParameter( 'am' );
00042 $sOrderId = oxConfig::getParameter( 'oxid' );
00043
00044
00045 $sQ = "select oxid from oxarticles where oxarticles.oxartnum = '{$sArtNum}'";
00046 if ( ( $sArtId = oxDb::getDb()->getOne( $sQ ) ) && $dAmount > 0 ) {
00047 $oOrderArticle = oxNew( 'oxorderArticle' );
00048 $oOrderArticle->oxorderarticles__oxartid = new oxField( $sArtId );
00049 $oOrderArticle->oxorderarticles__oxartnum = new oxField( $sArtNum );
00050 $oOrderArticle->oxorderarticles__oxamount = new oxField( $dAmount );
00051 $aOrderArticles[] = $oOrderArticle;
00052
00053 $oOrder = oxNew( 'oxorder' );
00054 if ( $oOrder->load( $sOrderId ) ) {
00055 $oOrder->recalculateOrder( $aOrderArticles );
00056 }
00057 }
00058 }
00059 }
00060
00066 public function deleteThisArticle()
00067 {
00068
00069 $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00070 $sOrderId = oxConfig::getParameter( 'oxid' );
00071
00072 $oOrderArticle = oxNew( 'oxorderarticle' );
00073 $oOrder = oxNew( 'oxorder' );
00074
00075
00076 if ( $oOrderArticle->load( $sOrderArtId ) && $oOrder->load( $sOrderId ) ) {
00077 $myConfig = $this->getConfig();
00078
00079
00080 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00081 $oOrderArticle->updateArticleStock( $oOrderArticle->oxorderarticles__oxamount->value, $myConfig->getConfigParam('blAllowNegativeStock') );
00082 }
00083
00084
00085 $oOrderArticle->delete();
00086
00087
00088 $oOrder->recalculateOrder();
00089 }
00090 }
00091
00097 public function storno()
00098 {
00099 $myConfig = $this->getConfig();
00100
00101 $sOrderArtId = oxConfig::getParameter( 'sArtID' );
00102 $oArticle = oxNew( 'oxorderarticle' );
00103 $oArticle->load( $sOrderArtId );
00104
00105 if ( $oArticle->oxorderarticles__oxstorno->value == 1 ) {
00106 $oArticle->oxorderarticles__oxstorno->setValue( 0 );
00107 $sStockSign = -1;
00108 } else {
00109 $oArticle->oxorderarticles__oxstorno->setValue( 1 );
00110 $sStockSign = 1;
00111 }
00112
00113
00114 if ( $myConfig->getConfigParam( 'blUseStock' ) ) {
00115 $oArticle->updateArticleStock( $oArticle->oxorderarticles__oxamount->value * $sStockSign, $myConfig->getConfigParam('blAllowNegativeStock') );
00116 }
00117
00118 $sQ = "update oxorderarticles set oxstorno = '{$oArticle->oxorderarticles__oxstorno->value}' where oxid = '{$sOrderArtId}'";
00119 oxDb::getDb()->execute( $sQ );
00120
00121
00122 $sQ = "select oxartid from oxorderarticles where oxid = '{$sOrderArtId}'";
00123 if ( ( $sArtId = oxDb::getDb()->getOne( $sQ ) ) ) {
00124 $oOrder = oxNew( 'oxorder' );
00125 if ( $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00126 $oOrder->recalculateOrder();
00127 }
00128 }
00129 }
00130
00136 public function updateOrder()
00137 {
00138 $aOrderArticles = oxConfig::getParameter( 'aOrderArticles' );
00139
00140 $oOrder = oxNew( 'oxorder' );
00141 if ( is_array( $aOrderArticles ) && $oOrder->load( oxConfig::getParameter( 'oxid' ) ) ) {
00142
00143 $myConfig = $this->getConfig();
00144 $oOrderArticles = $oOrder->getOrderArticles();
00145
00146 $blUseStock = $myConfig->getConfigParam( 'blUseStock' );
00147 foreach ( $oOrderArticles as $oOrderArticle ) {
00148 $sItemId = $oOrderArticle->getId();
00149 if ( isset( $aOrderArticles[$sItemId] ) ) {
00150
00151
00152 if ( $blUseStock ) {
00153 $oOrderArticle->setNewAmount( $aOrderArticles[$sItemId]['oxamount'] );
00154 } else {
00155 $oOrderArticle->assign( $aOrderArticles[$sItemId] );
00156 $oOrderArticle->save();
00157 }
00158 }
00159 }
00160
00161
00162 $oOrder->recalculateOrder();
00163 }
00164 }
00165 }