article_stock.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Stock extends oxAdminDetails
00010 {
00011 
00018     public function render()
00019     {
00020         $myConfig = $this->getConfig();
00021 
00022         parent::render();
00023 
00024         $this->_aViewData["edit"] = $oArticle = oxNew("oxarticle");
00025 
00026         $soxId = $this->getEditObjectId();
00027         if ($soxId != "-1" && isset($soxId)) {
00028 
00029             // load object
00030             $oArticle->loadInLang($this->_iEditLang, $soxId);
00031 
00032             // load object in other languages
00033             $oOtherLang = $oArticle->getAvailableInLangs();
00034             if (!isset($oOtherLang[$this->_iEditLang])) {
00035                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00036                 $oArticle->loadInLang(key($oOtherLang), $soxId);
00037             }
00038 
00039             foreach ($oOtherLang as $id => $language) {
00040                 $oLang = new stdClass();
00041                 $oLang->sLangDesc = $language;
00042                 $oLang->selected = ($id == $this->_iEditLang);
00043                 $this->_aViewData["otherlang"][$id] = clone $oLang;
00044             }
00045 
00046 
00047             // variant handling
00048             if ($oArticle->oxarticles__oxparentid->value) {
00049                 $oParentArticle = oxNew("oxarticle");
00050                 $oParentArticle->load($oArticle->oxarticles__oxparentid->value);
00051                 $this->_aViewData["parentarticle"] = $oParentArticle;
00052                 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00053             }
00054 
00055             if ($myConfig->getConfigParam('blMallInterchangeArticles')) {
00056                 $sShopSelect = '1';
00057             } else {
00058                 $sShopID = $myConfig->getShopID();
00059                 $sShopSelect = " oxshopid =  '$sShopID' ";
00060             }
00061 
00062             $oPriceList = oxNew("oxlist");
00063             $oPriceList->init('oxbase', "oxprice2article");
00064             $sQ = "select * from oxprice2article where oxartid = '{$soxId}' " .
00065                   "and {$sShopSelect} and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00066             $oPriceList->selectstring($sQ);
00067 
00068             $this->_aViewData["amountprices"] = $oPriceList;
00069 
00070         }
00071 
00072         return "article_stock.tpl";
00073     }
00074 
00078     public function save()
00079     {
00080         parent::save();
00081 
00082         $soxId = $this->getEditObjectId();
00083         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00084 
00085         // shopid
00086         $sShopID = oxRegistry::getSession()->getVariable("actshop");
00087         $aParams['oxarticles__oxshopid'] = $sShopID;
00088 
00089         $oArticle = oxNew("oxarticle");
00090         $oArticle->loadInLang($this->_iEditLang, $soxId);
00091 
00092         $oArticle->setLanguage(0);
00093 
00094         // checkbox handling
00095         if (!$oArticle->oxarticles__oxparentid->value && !isset($aParams['oxarticles__oxremindactive'])) {
00096             $aParams['oxarticles__oxremindactive'] = 0;
00097         }
00098 
00099         $oArticle->assign($aParams);
00100 
00101         //tells to article to save in different language
00102         $oArticle->setLanguage($this->_iEditLang);
00103         $oArticle = oxRegistry::get("oxUtilsFile")->processFiles($oArticle);
00104 
00105         $oArticle->resetRemindStatus();
00106 
00107         $oArticle->updateVariantsRemind();
00108 
00109         $oArticle->save();
00110     }
00111 
00120     public function addprice($sOXID = null, $aUpdateParams = null)
00121     {
00122         $myConfig = $this->getConfig();
00123 
00124         $this->resetContentCache();
00125 
00126         $sOxArtId = $this->getEditObjectId();
00127 
00128 
00129 
00130         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00131 
00132         if (!is_array($aParams)) {
00133             return;
00134         }
00135 
00136         if (isset($aUpdateParams) && is_array($aUpdateParams)) {
00137             $aParams = array_merge($aParams, $aUpdateParams);
00138         }
00139 
00140         //replacing commas
00141         foreach ($aParams as $key => $sParam) {
00142             $aParams[$key] = str_replace(",", ".", $sParam);
00143         }
00144 
00145         $aParams['oxprice2article__oxshopid'] = $myConfig->getShopID();
00146 
00147         if (isset($sOXID)) {
00148             $aParams['oxprice2article__oxid'] = $sOXID;
00149         }
00150 
00151         $aParams['oxprice2article__oxartid'] = $sOxArtId;
00152         if (!isset($aParams['oxprice2article__oxamount']) || !$aParams['oxprice2article__oxamount']) {
00153             $aParams['oxprice2article__oxamount'] = "1";
00154         }
00155 
00156         if (!$myConfig->getConfigParam('blAllowUnevenAmounts')) {
00157             $aParams['oxprice2article__oxamount'] = round(( string ) $aParams['oxprice2article__oxamount']);
00158             $aParams['oxprice2article__oxamountto'] = round(( string ) $aParams['oxprice2article__oxamountto']);
00159         }
00160 
00161         $dPrice = $aParams['price'];
00162         $sType = $aParams['pricetype'];
00163 
00164         $oArticlePrice = oxNew("oxbase");
00165         $oArticlePrice->init("oxprice2article");
00166         $oArticlePrice->assign($aParams);
00167 
00168         $oArticlePrice->$sType = new oxField($dPrice);
00169 
00170         //validating
00171         if ($oArticlePrice->$sType->value &&
00172             $oArticlePrice->oxprice2article__oxamount->value &&
00173             $oArticlePrice->oxprice2article__oxamountto->value &&
00174             is_numeric($oArticlePrice->$sType->value) &&
00175             is_numeric($oArticlePrice->oxprice2article__oxamount->value) &&
00176             is_numeric($oArticlePrice->oxprice2article__oxamountto->value) &&
00177             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00178         ) {
00179             $oArticlePrice->save();
00180         }
00181 
00182         // check if abs price is lower than base price
00183         $oArticle = oxNew("oxArticle");
00184         $oArticle->loadInLang($this->_iEditLang, $sOxArtId);
00185         $sPriceField = 'oxarticles__oxprice';
00186         if (($aParams['price'] >= $oArticle->$sPriceField->value) &&
00187             ($aParams['pricetype'] == 'oxprice2article__oxaddabs')) {
00188             if (is_null($sOXID)) {
00189                 $sOXID = $oArticlePrice->getId();
00190             }
00191             $this->_aViewData["errorscaleprice"][] = $sOXID;
00192         }
00193 
00194     }
00195 
00199     public function updateprices()
00200     {
00201 
00202         $aParams = oxRegistry::getConfig()->getRequestParameter("updateval");
00203         if (is_array($aParams)) {
00204             foreach ($aParams as $soxId => $aStockParams) {
00205                 $this->addprice($soxId, $aStockParams);
00206             }
00207         }
00208     }
00209 
00210 
00214     public function deleteprice()
00215     {
00216         $this->resetContentCache();
00217 
00218         $oDb = oxDb::getDb();
00219         $sPriceId = $oDb->quote(oxRegistry::getConfig()->getRequestParameter("priceid"));
00220         $sId = $oDb->quote($this->getEditObjectId());
00221         $oDb->execute("delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}");
00222     }
00223 }