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
00030 $oArticle->loadInLang($this->_iEditLang, $soxId);
00031
00032
00033 $oOtherLang = $oArticle->getAvailableInLangs();
00034 if (!isset($oOtherLang[$this->_iEditLang])) {
00035
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
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
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
00095 if (!$oArticle->oxarticles__oxparentid->value && !isset($aParams['oxarticles__oxremindactive'])) {
00096 $aParams['oxarticles__oxremindactive'] = 0;
00097 }
00098
00099 $oArticle->assign($aParams);
00100
00101
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
00125 $sOxArtId = $this->getEditObjectId();
00126
00127
00128
00129 $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00130
00131 if (!is_array($aParams)) {
00132 return;
00133 }
00134
00135 if (isset($aUpdateParams) && is_array($aUpdateParams)) {
00136 $aParams = array_merge($aParams, $aUpdateParams);
00137 }
00138
00139
00140 foreach ($aParams as $key => $sParam) {
00141 $aParams[$key] = str_replace(",", ".", $sParam);
00142 }
00143
00144 $aParams['oxprice2article__oxshopid'] = $myConfig->getShopID();
00145
00146 if (isset($sOXID)) {
00147 $aParams['oxprice2article__oxid'] = $sOXID;
00148 }
00149
00150 $aParams['oxprice2article__oxartid'] = $sOxArtId;
00151 if (!isset($aParams['oxprice2article__oxamount']) || !$aParams['oxprice2article__oxamount']) {
00152 $aParams['oxprice2article__oxamount'] = "1";
00153 }
00154
00155 if (!$myConfig->getConfigParam('blAllowUnevenAmounts')) {
00156 $aParams['oxprice2article__oxamount'] = round(( string ) $aParams['oxprice2article__oxamount']);
00157 $aParams['oxprice2article__oxamountto'] = round(( string ) $aParams['oxprice2article__oxamountto']);
00158 }
00159
00160 $dPrice = $aParams['price'];
00161 $sType = $aParams['pricetype'];
00162
00163 $oArticlePrice = oxNew("oxbase");
00164 $oArticlePrice->init("oxprice2article");
00165 $oArticlePrice->assign($aParams);
00166
00167 $oArticlePrice->$sType = new oxField($dPrice);
00168
00169
00170 if ($oArticlePrice->$sType->value &&
00171 $oArticlePrice->oxprice2article__oxamount->value &&
00172 $oArticlePrice->oxprice2article__oxamountto->value &&
00173 is_numeric($oArticlePrice->$sType->value) &&
00174 is_numeric($oArticlePrice->oxprice2article__oxamount->value) &&
00175 is_numeric($oArticlePrice->oxprice2article__oxamountto->value) &&
00176 $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00177 ) {
00178 $oArticlePrice->save();
00179 }
00180
00181
00182 $oArticle = oxNew("oxArticle");
00183 $oArticle->loadInLang($this->_iEditLang, $sOxArtId);
00184 $sPriceField = 'oxarticles__oxprice';
00185 if (($aParams['price'] >= $oArticle->$sPriceField->value) &&
00186 ($aParams['pricetype'] == 'oxprice2article__oxaddabs')) {
00187 if (is_null($sOXID)) {
00188 $sOXID = $oArticlePrice->getId();
00189 }
00190 $this->_aViewData["errorscaleprice"][] = $sOXID;
00191 }
00192
00193 }
00194
00198 public function updateprices()
00199 {
00200
00201 $aParams = oxRegistry::getConfig()->getRequestParameter("updateval");
00202 if (is_array($aParams)) {
00203 foreach ($aParams as $soxId => $aStockParams) {
00204 $this->addprice($soxId, $aStockParams);
00205 }
00206 }
00207 }
00208
00209
00213 public function deleteprice()
00214 {
00215
00216 $oDb = oxDb::getDb();
00217 $sPriceId = $oDb->quote(oxRegistry::getConfig()->getRequestParameter("priceid"));
00218 $sId = $oDb->quote($this->getEditObjectId());
00219 $oDb->execute("delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}");
00220 }
00221 }