order_article.php

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